Reading Errors
Mistakes are a normal part of programming. Even experienced programmers make them every day. What matters is finding and fixing them quickly, and error messages help you with that.
When JavaScript can't run your program, it shows a red error message below the output. Read it carefully: it has two parts. For example:
ReferenceError: prise is not defined- Before the colon is the type of the error, here
ReferenceError. - After the colon is a description of what went wrong. This one says that
priseisn't defined, so JavaScript doesn't know this name.
The most common types of errors are:
SyntaxError: the code breaks the rules for writing JavaScript, its syntax. Usually a quote or a parenthesis is missing. For example,console.log("Hi";ends withSyntaxError: missing ) after argument list, which says that a closing parenthesis is missing. A missing quote givesSyntaxError: Invalid or unexpected token. JavaScript checks the whole program before running it, so when there is a syntax error, nothing runs at all, not even the lines before the mistake.ReferenceError: you used a name that JavaScript doesn't know. Usually it's a typo (priseinstead ofprice, orPrice, because uppercase and lowercase letters matter), a variable used before it was created, or text without quotes:console.log(Anna).TypeError: you tried to do something that the value doesn't allow, such as changing a constant:TypeError: Assignment to constant variable.
With a ReferenceError or a TypeError, the program runs until it reaches the mistake, and then it stops. What it printed before stays in the output. That's a useful clue: the mistake is after the last console.log() that still printed something.
The descriptions here are the ones Chrome shows. Other browsers word them a little differently, but the type of the error is the same everywhere.
When you get an error, read its type and description, find the place in the code it's about, and fix it. Then run the program again: there may be another mistake further on.
Instructions
The program in the editor has two mistakes. Run it, read the error message, fix the mistake and run the program again. Repeat this until the program prints:
Player: Anna
Points: 10
Points after the bonus: 15Start programming for free
11/12