in jsLint i keep getting this 5 errors :
'Unexpected '(space)' case summer.
'Unexpected '(space)' case winter.
'Unexpected '(space)' case fall.
'Unexpected '(space)' case autumn.
'Unexpected '(space)' case spring.
var season = prompt("what is your favourite season");
switch (season) {
case "summer":
alert("i love summer too");
break;
case "winter":
alert("i love winter too ");
break;
case "spring":
alert("i love Spring too");
break;
case "fall":
alert("i love Fall too");
break;
case "autumn":
alert("i love autumn too");
break;
There's enough going on here that it's probably best to point you to the JSLint instructions to see what's going on for the future. You can find them here: http://jslint.com/help.html
But here's what's up for your question...
TL;DR: Mainly it's complaining that you have trailing spaces after your
casestatements.Turn this...
... into this...
Longer:
You could get around your spacing errors by adding a JSLint Directive to the top of your file. The one you want here is
white:true, which indicates that you want to, "Tolerate whitespace mess".But now you'll have a whole slew of new things to fix...
The first is easy enough; you just wrap in a function.
The second two are there because you haven't told JSLint what context to expect, and it's not sure if
alertandpromptare valid calls. You could tell italertandpromptare globals with another type of directive, the global directive, but remember that...So to use the globals directive, you also need to set the
browserdirective in the jslint comment we added earlier.Believe it or not, this mess, below, already lints! Try it at JSLint.com.
But
promptandalertare special cases. Those are functions you'll use during browser development. Instead of setting them up in the global directive, use thedeveldirective like this...I'm also going to take off the
white:trueand clean this thing up so that it's readable... Note that there are no trailing spaces, and that we have thecasestatements lined up with theswitch, which initially seemed odd to me.And now we have a JSLint-happy, cleanly whitespaced piece of code. I'd probably move the
alertto the end and assign values to a string in your switch, but JSLint is already happy.Hope that helps, and gives you a little jump-start for using JSLint.