I used to generate a memorable number (var = randomDigit) using math.random for a school assignment I'm making a JavaScript number game. Ask the user to think of more than 1 number. Basically, they double their number and JS doubles my random number and outputs it. They combine the numbers together, then divide them by two and leave me their original number (var = randomDigit)
Here's the part where I got stuck. I have to do this, if the user does not want to play, he will not run ... and I can use only one "if" statement I opted to use a prompt () method ... and if you If you type in yes then it works, like the dialogue says and if you cancel it then it does not work (good news). But if I type in "no" like I do not want to play games, it still works
I want it so the program only works with "yes" typed in quick conversation Does.
These are my JS Freadal:
function dialog () {var x; Var randomDigit = Math.floor ((Math.random (* * 20) +1); Var doubleDigit = + randomDigit * 2; Var play = prompt ("Do you want to play games? If not, then press Cancel below. \ N \ n Take care of more than 1. You need to think about a number by typing the word: Yes" , "Type here"); If (play === 'false') {document.getElementById ("pick") InnerHTML = "Sorry, maybe next time."; } And (play = "yes"); {X = "1". Now repeat the number that you thought I'm also going to think about a number: "+ + '+ Double Diagnosis +'
'+" 2 Now add my number and my doubly number together. "+ '
< + "Now divide the sum numbers by 2, then reduce your original number. Do you get "+ + + Random" + "Digit +"? + '& Lt; br & gt; & lt; br & gt; + "Very good, right?"; Document.getElementById ("take") innerHTML = X.}}
Minor tweaks
if (game ==" yes ") {x =" 1. Now repeat the number you think about. I'm also going to think of a number: "+ + 'Dual Diagram +' & lt; br & gt; & lt; br & gt; '+" 2. Now add my number and my doubly number together. "+ '
< + "Now divide the sum numbers by 2, then reduce your original number. Do you get "+ + + Random" + "Digit +"? + '& Lt; br & gt; & lt; br & gt; + "Very good, right?"; Document.getElementById ("pick") innerHTML = X.} and {document.getElementById ("pick"). InnerHTML = "Sorry, maybe next time.";} Demo:
No comments:
Post a Comment