File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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+
You can’t perform that action at this time.
0 commit comments