Skip to content

Commit bcff939

Browse files
committed
done exercises decimal.js
1 parent 45eab06 commit bcff939

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Sprint-1/exercises/decimal.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@ const num = 56.5678;
33
// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
44

55
// Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num )
6+
7+
const wholeNumberPart = (Math.floor(num));
8+
9+
610
// Create a variable called decimalPart and assign to it an expression that evaluates to 0.5678 ( the decimal part of num )
11+
12+
// parseFloat() picks the longest substring starting from the beginning that generates a valid
13+
// number literal. If it encounters an invalid character, it returns the number represented up
14+
// to that point, ignoring the invalid character and all characters following it.
15+
// If the argument's first character can't start a legal number literal per the syntax above,
16+
// parseFloat returns NaN.
17+
18+
const decimalPart = parseFloat((num - wholeNumberPart).toFixed(4));
19+
20+
721
// Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number )
822

23+
24+
const roundedNum = (Math.round(num));
25+
926
// Log your variables to the console to check your answers
27+
console.log(wholeNumberPart, decimalPart, roundedNum);
28+

0 commit comments

Comments
 (0)