I am creating a guessing game, and I need help with refreshing the font after every correct guess the user makes. I set up my code so that the font changes every time the page is refreshed:
<script>
var fontType =
[ "Arial", "Verdana", "Helvetica", "Times New Roman", "Arial Black", "Comic
Sans", "Georgia", "Tahoma", "Comic Sans MS"];
var num;
num=Math.floor(Math.random()*9);
document.getElementById("fontfamily").style.fontFamily =fontType[num];
console.log(num)
</script>
This works successfully. This is the code I have set up for when the user/player is guessing:
function Correct() {
var correct = ""; // correct answer
var guess = ""; // user guess
var NumberOfGuesses = 0;
guess=document.getElementById("guess").value;
correct=document.getElementById("fontfamily").style.fontFamily;
if (guess == correct && NumberOfGuesses <3) {
alert("Correct! The font is " + correct + " . On to the next one!");
} else {
alert("that's not it...try again");
NumberOfGuesses = NumberOfGuesses + 1;
}
}
What could I do so that every time the user guesses correctly, the font automatically randomizes again? I appreciate the help.
Put the randomization code in the first block into a function. Call this function every time the User guesses correctly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.