The browser storage localStorage is not available. Either your browser does not support it or you have disabled it or the maximum memory size is exceeded. Without localStorage your solutions will not be stored.
Numbers
Numbers are represented by simple numerals. They can have a decimal point and a minus sign.
let x1 = 1;
let x2 = 1.0;
let x3 = 3.14;
let x4 = -1;
1
and 1.0
are the same number.
You can calculate with numbers. The four basic arithmetics adding, subtracting, multiplying and dividing are represented by
+ - *
and /
.
let x1 = 6;
let x2 = 2;
let x3 = x1 + x2;
let x4 = x1 - x2;
let x5 = x1 * x2;
let x6 = x1 / x2;
The variables x3
to x6
thus have the values 8
, 4
, 12
and 3
.Exercise
Write a function
Example:
add
that takes two numbers and returns their sum.Example:
add(1, 2)
should return 3
.
+ Hint
function add(x, y) {
return ...
}
+ Solution
function add(x, y) {
return x + y;
}