Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active February 13, 2024 23:44
Show Gist options
  • Save ross-u/90751f64475a77095eace5cdc49ed93a to your computer and use it in GitHub Desktop.
Save ross-u/90751f64475a77095eace5cdc49ed93a to your computer and use it in GitHub Desktop.
JS | Data types Numbers - Math warm up - Exercise

JS | Data types Numbers

Math warm up - Exercise


img


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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment