so I've been working on functions making star patterns and somehow I keep getting "undefined" when i ´innerHTML´ it. Can anyone help me to see what I'm doing wrong here?
pOutput.innerHTML = square(3);
poutput.innerHTML = rectangle(2,3);
function square(x) {
var z;
for (var i = 1; i<=x; i++) {
for ( var j = 1; j<=x; j++) {
z += "*";
}
z += "<br>";
}
return z
}
function rectangle(x, y) {
var z;
for (var i = 1; i<=x; i++) {
for ( var j = 1; j<=y; j++) {
z += "*";
}
z += "<br>";
}
return z
}
var z;<--- undefined....;to your returns. Also don't name variables that only differ with case (poutput vs pOutput). poutput isn't a very descriptive name anyway. Your first function can also be shortened down to 1 line:return rectangle(x, x);:-)