Exercises
Recap Questions
What is the syntax for representing human speech in JavaScript?
We use strings, for instance 'To be or not to be', 'Ophelia', "It's time to go!".
Strings are enclosed either in single quotes or double quotes. Double quotes are useful if you need to include single quotes or apostrophes in the string itself.
How do we print out information in JavaScript?
With console.log, like:
console.log('The sum of 2 and 3 is', 2 + 3);
What happens if we forget to close the parenthesis after console.log?
The machine won't know how to parse your code, and will generate an output of the following kind:
'SyntaxError: /index.js: Unexpected token, expected , (2:0)
How do you perform mathematical operations in JavaScript?
With mathematical operators, for instance:
console.log(2 + 3); console.log(7 * 5); console.log(5 - 4); console.log(8 / 10);
Toggle Console Output
- 5
- 35
- 1
- 0.8