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()
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 2 years ago.
Improve this question
Hi im pretty sure what im about to post might not be enough info (if so please let me know what more is needed). I am using node js and having a really weird error. Below is the code and output.
if (currentPrice > variableData[i].stopLossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
Output:
if
92.7
is more than
93.62700000000001
This is consistently happening. I also made sure that both currentPrice and variableData[i].stopLossHard are numbers and not strings (I made sure in the code and in the output its the color of a number not a string)
Any ideas is highly appreciated.
The attribute you print is different than the one you check in the if statement:
(In the if stopLossHard has a capital L, stop-L-ossHard, what you print doesn't)
Try this:
if (currentPrice > variableData[i].stoplossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
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
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 '}'
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!
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 have json data I'm having difficulty turning into a string. How can I format it so that it can become strings?
jsfiddle: http://jsfiddle.net/s97QX/2/
code:
Jsonvar = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's Dilemma","guest":"Devin Rose","category":"Non-Catholic","url":"http://www.catholic.com/radio/shows/the-protestants-dilemma-11565","audiourl":"http://www.catholic.com/sites /default/files/audio/radioshows/ca140331b.mp3","datetime":"1396317600","description":"
Devin Rose <\/p>","thumbnailsmall":"http://www.catholic.com/sites/default/files/imagecache/profile_square_small/images/profilepics/a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg","thumbnaillarge":"http://www.catholic.com/sites/default/files/imagecache/profile_square_large/images/profilepics /a109aad8daa70ad8976ffc.L._V387899120_SX200_.jpg"}]};
var jsonstr=JSON.stringify(Jsonvar);
alert(jsonstr);
First You validate your json using jsonlint.
JSONLINT
then try.
This error in the console explains it:
Uncaught SyntaxError: Unexpected token ILLEGAL
You have a line break in your object:
Jsonvar = {"shows":[{"show_id":6387, "shownum":6387,"title":"The Protestant's Dilemma","guest":"Devin Rose","category":"Non-
Catholic","url":"http://www.catholic.com/radio/shows/the-protestants-dilemma-
11565","audiourl":"http://www.catholic.com/sites/default/files/audio/radioshows/ca140331b.mp3"
,"datetime":"1396317600","description":" <<<- Here
Devin Rose
Remove that and that property will become a valid string, therefore you'll be able to stringify it