//So I am brand spanking new to javascript (like, I've been dropped into the deep end for this for my intro to engineering class with only my wits and the p5.js references), so forgive me if this question is obvious to you, because it's stumping my teammate and I.//
I am making a game where you are given a randomized phone number and you have to use some numbered buttons to type in the random number to win. We have managed to get that part to work, after a bit of head scratching, but I can't seem to figure out how to get the number to reset after someone wins the game. What we're working on right now is making the win state nicer than just a bit of text saying "you win" or "you lose" with nothing else to follow. Our plan is to have a screen pop up that gives you the option to play again or go to the home screen to choose another game to play. Since I'm the one who figured out how to get the phone number to randomize, I need to figure out how to get it to reset. If you guys could help, I'd very much appreciate it.
this is what I have for my generator so far:
let number1, number2, number3, number4, number5, number6, number7, number8, number9, number0, randNum;
function getRandomInt() {
return Math.floor(Math.random() * 10);
}
number0 = getRandomInt();
number1 = getRandomInt();
number2 = getRandomInt();
number3 = getRandomInt();
number4 = getRandomInt();
number5 = getRandomInt();
number6 = getRandomInt();
number7 = getRandomInt();
number8 = getRandomInt();
number9 = getRandomInt();
randNum = '(' + number0 + number1 + number2 + ') ' + number3 + number4 + number5 + '-' + number6 + number7 + number8 + number9;
When I had the variables to create a random number in a function, they would be randomizing constantly, and when I took them out, they were set, but now that they're outside of a function, I don't know how to get them to reset.
Aucun commentaire:
Enregistrer un commentaire