Write the JavaScript to prompt the user to enter an odd number. First, check that the user has entered a valid odd number. Then you need to print to the console a cross made of the same number of * characters as the number the user entered.
So far I have my code as such
I've edited my code to include the proper way
let num = prompt("Enter an odd number");
let star = "*";
let vertical = "";
let horizontal = star.repeat(num);
while (num%2 == 0) {
console.log("User did not enter an odd number");
num = prompt("Enter an odd number");
}
console.log("User's number is " +num);
let pos = +(Math.ceil(num/2));
// I need to divide the input number by 2 and round up
for (var h = 0; h < pos; h++){
vertical += (" ")
}
for (var v = 0; v < pos; v++){
vertical += vertical + "\n *"
}
vertical += "*"
console.log (vertical)
I can get vertical to \n the proper amount of times but how would I go about making sure I don't over repeat the *?
let vertical = ""and then after the loop writevertical += "*"?