For this exercise you will use Repl.it. Before starting create an account and create a new repl by clicking + new repl.
Task 1
Using the method Math.random()
return a random number between 0 and 20.
The returned number must be a integer (rounded number without decimals).
You can round the number by using either Math.ceil()
or Math.floor()
.
var result = /* Your code here */;
console.log(result);
Task 2
Using console log and Math.min()
and Math.max()
return the lowest and the highest from the following set of numbers: 100, 874, 2343, 34, -9547, 0, 9234, 435, -23
.
// Numbers set: 100, 874, 2343, 34, -9547, 0 9234, 435, -23
console.log(); // Print the lowest number
console.log(); // Print the highest number
Task 3
Fix the floating point precision issue of the variable num.
The printed value of num
should be a string "0.003"
.
Check the method .toFixed().
var num = 0.1 + 0.2;
console.log(num);