'Trying to make a random number guesser on javascript and its showing a syntax error. Anyone know a fix?
Heres my code:
function TheNumber(){
let Number = Math.floor(Math.random() * 10) + 1
DaGuess()
}
function DaGuess(){
let Guess = prompt('Pick your number between 1 - 100')
if (Guess > Number){
alert('Try picking a number lower than ' + this.Guess)
DaGuess()
}
if (Guess < Number){
alert('Try picking a number higher than ' + this.Guess)
DaGuess()
}
if (Guess == Number){
let playagain = prompt('Well done! Wanna play again? Y/N')
if (playagain == 'Y' or playagain == 'y'){
TheNumber()
}
}
else{
alert('Thanks for playing!')
}
}
TheNumber()
SyntaxError: Unexpected identifier at /script.js:19:26
Im completely new to javascript so if the code is awful i am sorry. Any help would be greatly appreciated.
Solution 1:[1]
Theor keyword doesn't exist in JS, you must use ||.
if (playagain === 'Y' || playagain === 'y'){
TheNumber()
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peterrabbit |
