Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am learning JavaScript on codeacademy and I came upon an error as I was doing a lesson and I could not figure out how to fix it. The error was
SyntaxError: Unexpected token else.
Here is my code:
sleepCheck = function (numHours) {
if (sleepCheck >= 8) {
return "You're getting plenty of sleep! Maybe even too much!";
} ;
else {
return "Get some more shut eye!";
} ;
} ;
sleepCheck(10) ;
sleepCheck(5) ;
sleepCheck(8) ;
This was supposed to be a sleep checker. I was learning about functions and the return keyword.
The issue is the ';' before the else and after the '}'
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
i am uisang this code:
Class Addition {
constructor () {
}
add (a = 1, b = 1) {
console.log(a+b)
}
}
but it geeve aan error
Uncaught SyntaxError: Unexpected identifier
Syntax is wrong, class should be in lowercase:
class Addition {
constructor () {
}
add (a = 1, b = 1) {
console.log(a+b)
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to get the console to read "No goal!" but every time I run it, I get "Goal". I'm guessing there's some basic syntax error that I'm making?
let isSoccerFan = false;
if (isSoccerFan=true) {
console.log("Goal!");
} else{
console.log("No goal!")
}
Your code is not correct. Try this:
let isSoccerFan = false;
if (isSoccerFan) {
console.log('Goal!');
} else {
console.log('No goal!');
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
So, me and a few friends are making a text adventure in JavaScript. in it, there is a possibility of the player using a heal spell, which runs the following code:
function heal() {
alert('You chant some ominous-sounding words, and your wounds heal');
alert('Hit points restored!');
hitPoints += 60;
blobsOfDoom -= 30;
burn();
MonsAtt();
Choose Spell();
}
Error Messages:
Firefox:
/*
Exception: SyntaxError: missing ; before statement
#Scratchpad/1:2703
*/
Chrome:
SyntaxError: Unexpected identifier.
Why is this error showing up? How do I fix it?
You cant have spaces in functions
Choose Spell();
Check your function declaration for ChooseSpell and any other occurances, and change them to a valid function name, like chooseSpell()
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Can't figure out what I'm doing wrong... here is my jquery code
<script>
$("#validationForm").submit(function(event) {
alert('test');
};
</script>
$("#validationForm").submit(function(event) {
alert('test');
};
^
Should be:
$("#validationForm").submit(function(event) {
alert('test');
});
If you see this error in your browser's Dev Tools, try clicking in its line, like: Syntax Error: Uncaught SyntaxError: missing ) after argument list file.js:1. When 1 is the line. It will show you where the error is.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
While I'm trying to write a simple function which need to iterate through classes of event.target and do something depending of class name, I've encountered unknown error (as for me).
function tPager() {
var lc = $(event.target).attr('class');
swith(lc) {
case ('slow'):
console.log('slowclicked');
break;
case ('page'):
console.log('pageclicked');
break;
}
};
This is just for testing purposes, console will always say "Unexpected token", there is an error in line 3, "{". Can't get what's wrong.
JSFiddle: http://jsfiddle.net/2cJhC/
Wouldn't the code be like this
switch(lc) { // note the keyword switch
case 'slow':
console.log('slowclicked');
break;
case 'page':
console.log('pageclicked');
break;
}
You're currently having this
swith(lc) { // that is not switch keyword.
The mistake actual, was at the keyword usage. You were having the wrong keyword that was triggering the mistake. Change it, and its good to go!