I try to compile this .coffee file into .js, but it gives me error:
In projekt.coffee, Parse error on line 122: Unexpected '='
here is the specific part:
#line122 -># quotes = ["The people who were trying to make this world worse are not taking the day off. Why should I? <br> -Bob Marley", "Don't worry about a thing, every little thing is gonna be alright<br> -Bob Marley", "Better to die fighting for freedom then be a prisoner all the days of your life.<br> -Bob Marley", "Herb is the healing of a nation, alcohol is the destruction of mankind<br> -Bob Marley", "When you smoke the herb, it reveals you to yourself.<br> -Bob Marley", "My music fights against the system that teaches to live and die.<br> -Bob Marley"]
quoteNumber = Math.floor(Math.random() * quotes.length)
$('#cytat').html '<p> #{quotes[quoteNumber]} <p>'.css
font-family : Finger Paint
ande here the whole code:
i dont really know whats going on since it tells me that ‘=’ is unexpected, but it clearly defines an array. help…
There are multiple problems with this that we should address before the syntax error you’re describing.
font-familyis not a valid stand-alone key. You need to quote that in order to compile it correctly. Same withFinger Paint— I don’t know what’s up with that.String interpolation doesn’t work with single quoted strings. You need to use double quotes if you want
#{quotes[quoteNumber]}to be replaced with the quote at that index.With these fixed, we still have a big problem with operator precedence:
That’s equivalent to:
Which is probably not what you meant, since strings don’t have a
.css()method. Add parens around the.html()call to get it to the correct meaning:Now, finally, the syntax error. At first glance, this appears to be perfectly valid code, and the error message isnt’ very helpful… but this code has a fatal mistake. Do you see it? There’s nothing wrong with the sample you posted; this is only wrong in the context of the rest of the file. So what is it?
You’ve mixed tabs and spaces. Never mix tabs and spaces. The CoffeeScript compiler is apparently using a different tab width than your editor, so it freaks out, and gives you a crazy error message.
Consider using a text editor that will automatically translate tabs into (a consistent number of) spaces, or at the very least one that allows you to view invisible characters. I like Sublime Text, but there are plenty of options out there.