Skip to content

Commit 1d5cb9d

Browse files
author
Edward King
committed
Part 1 Complete
1 parent b3319a2 commit 1d5cb9d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
let num = 1001;
22

33
//Returns 'undefined'.
4-
console.log(num.length);
4+
//console.log(num.length);
55

66
//Use type conversion to print the length (number of digits) of an integer.
77

8-
//Follow up: Print the number of digits in a DECIMAL value (e.g. num = 123.45 has 5 digits but a length of 6).
8+
console.log(String(num).length);
9+
910

11+
//Follow up: Print the number of digits in a DECIMAL value (e.g. num = 123.45 has 5 digits but a length of 6).
12+
num = 123.45
13+
console.log(String(num).length-1);
1014
//Experiment! What if num could be EITHER an integer or a decimal? Add an if/else statement so your code can handle both cases.
15+
if (String(num).includes('.')){
16+
console.log(String(num).length-1);
17+
} else {
18+
console.log(String(num).length);
19+
}
20+

0 commit comments

Comments
 (0)