最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript "Uncaught SyntaxError: Unexpected token ;" error - Stack Overflow

programmeradmin4浏览0评论

When i run this code it gives a syntax error in Chrome.

var leanboo = confirm("RFT(ready for testing)?") // Co1,Cr1
console.log(leanboo)
var text = prompt("What are your thoughts of this Area?")
console.log(text)

function crashCourseTesterIdGenerator(min, max) {
console.log(Math.floor((Math.random() * max) + min);)
} //Co1,Cr2
var testermin = prompt("Id generating min:")
var testermax = prompt("Id generating max:")
console.log(crashCourseTesterIdGenerator(testermin, testermax))

Does it have to do with the method name length or am i just forgetting some semicolons?

When i run this code it gives a syntax error in Chrome.

var leanboo = confirm("RFT(ready for testing)?") // Co1,Cr1
console.log(leanboo)
var text = prompt("What are your thoughts of this Area?")
console.log(text)

function crashCourseTesterIdGenerator(min, max) {
console.log(Math.floor((Math.random() * max) + min);)
} //Co1,Cr2
var testermin = prompt("Id generating min:")
var testermax = prompt("Id generating max:")
console.log(crashCourseTesterIdGenerator(testermin, testermax))

Does it have to do with the method name length or am i just forgetting some semicolons?

Share Improve this question asked Nov 18, 2013 at 19:11 ooransoyooransoy 7975 gold badges10 silver badges26 bronze badges 5
  • 2 This question appears to be off-topic because it is about a simple typographic error. – Pointy Commented Nov 18, 2013 at 19:12
  • 1 @Pointy, but you still answered it anyway? Kind of defeats the purpose of dissuading newers to post this type of question if you're just going to answer it anyway. – maček Commented Nov 18, 2013 at 19:13
  • @maček well the point of closing "typo questions" is that they don't do anybody any good as a long-term reference question, but this person still had a problem to be solved. I suppose I could have just typed a ment. I didn't put a lot of deep thought into the situation :) – Pointy Commented Nov 18, 2013 at 19:14
  • 1 Aside from the obvious syntax error, presumably you have put the console.log there to see why it's not working - if it isn't obvious the function has no return statement. – Emissary Commented Nov 18, 2013 at 19:15
  • jslint. or jshint. or use your debugger which will point you to the line. – epascarello Commented Nov 18, 2013 at 19:15
Add a ment  | 

3 Answers 3

Reset to default 6

You've got a ; inside the console.log() call in that function.

var leanboo = confirm("RFT(ready for testing)?"); // Co1,Cr1
console.log(leanboo);
var text = prompt("What are your thoughts of this Area?");
console.log(text);

function crashCourseTesterIdGenerator(min, max) {
console.log(Math.floor((Math.random() * max) + min));
} //Co1,Cr2
var testermin = prompt("Id generating min:");
var testermax = prompt("Id generating max:");
console.log(crashCourseTesterIdGenerator(testermin, testermax));

Should fix ya right up.

Semi colons go at the end of each statement in Javascript. You're missing them.

They're not strictly required, but you can mit all kinds of hard-to-find errors without them where Javascript doesn't know when one statement ends and another begins. Best to make it a matter of personal law to always use them and you're future self will save lots of debugging time.

And then you have an extra one:

console.log(Math.floor((Math.random() * max) + min);)

before the end of the line. Which is actually causing the error message.

发布评论

评论列表(0)

  1. 暂无评论