Challenge 1 +25 XP
Create a variable `total` equal to 50 multiplied by 2. Print it.
- Test 1 — expects "100"
Need a hint? (−25% XP)
Use the * operator for multiplication.
Show solution (0 XP)
let total = 50 * 2;
console.log(total); Most languages separate integers from decimals and make you keep track of which is which. JavaScript has one Number type for both. Every number you write — 42, 3.14, a loop counter, a price — is stored the same way: as a double-precision 64-bit float, following the IEEE 754 standard.
One type means no casting and no integer-versus-float bugs. It also means the decimal quirks of floating point apply to every number in the language, including ones that look like plain whole numbers.
JavaScript supports all the standard arithmetic operators you would expect:
+)-)*)/)let sum = 10 + 5;
console.log(sum);15
The remainder operator (%) returns the amount left over when one number is divided by another. It is often used to check if a number is even or odd.
console.log(10 % 3);1
To quickly add or subtract 1 from a variable, you can use the increment (++) and decrement (--) operators.
let count = 0;
count++;
console.log(count);1
Divide by zero in most languages and you get an exception. Multiply a word by a number and you get another one. JavaScript does neither.
The language was built to run inside a web page, where a fault in one small script should not take the page down with it. So instead of throwing, JavaScript absorbs impossible arithmetic into special numeric values and keeps going.
If you try to divide a positive number by zero, JavaScript returns the special value Infinity instead of crashing.
console.log(10 / 0);Infinity
Similarly, when you try to perform a mathematical operation that fundamentally doesn’t make logical sense—such as dividing a word by a number—JavaScript absorbs the error and returns a special value called NaN (Not-A-Number).
console.log("hello" / 2);NaN
The name says Not-A-Number, so the obvious guess is that it sits outside the number type — somewhere near undefined. Check it:
Read the code. What exactly will it print? Commit to an answer before you look.
console.log(typeof NaN);number
Despite its contradictory name, NaN is technically categorized as a numeric value within JavaScript’s underlying type system! It is best understood as a “corrupted number state”.
Not crashing has a cost. NaN is contagious: every arithmetic operation touching it produces NaN in turn, so a single bad value silently travels the length of a calculation and surfaces at the end, far from wherever it came from. Worse, NaN is the only value in JavaScript not equal to itself — NaN === NaN is false — so testing for it needs Number.isNaN(x).
Here is a simple visualization of how standard numbers, infinity, and NaN all fit harmlessly inside the single JavaScript Number type:
Which arithmetic operator gives the remainder of a division?
% — The remainder (%) operator returns the remainder left over when one operand is divided by a second operand.
What does the ++ operator do?
Adds one to its operand — The increment (++) operator increments (adds one to) its operand.
What is the result of typeof NaN?
"number" — Despite its name, NaN (Not-A-Number) is formally a numeric data type in JavaScript.
Create a variable `total` equal to 50 multiplied by 2. Print it.
Use the * operator for multiplication.
let total = 50 * 2;
console.log(total); Divide the string 'apples' by 2 and print the result, which should be NaN.
Math on a non-numeric string results in NaN.
console.log('apples' / 2);