Im doing really well, I just need a little help now. I have it so the computer makes a number, and it prompts the user the question, and it says if its right, or if you need to guess higher or lower. I need it to prompt again. Guidance please.
button to start game ----> Round
function round() {
var CN = Math.random();
CN = CN * 10;
var CN = Math.round(CN);
console.log(CN);
document.write('Computer has made a number.');
var PG = prompt("Pick a number 1 - 10");
if (PG == CN) {
document.write('You got it right!');
}
else if (PG < CN) {
document.write('Guess higher.');
}
else {
document.write('Guess lower.');
}
};
Usually we use for loops when you know how many loops we want to make - we would do something like:
for (var i = 0; i <= 5; i++) {
Since you have no idea how many guesses it will take your player, that makes this a good place for a while loop – you want to keep looping while guess is false.
I bet you can find the syntax for a while loop easily enough.
Yes, but if you aren’t sure about any then you should specifically ask so we can talk you through the difference between setting a value and comparing values.