File tree 1 file changed +12
-2
lines changed
stringing-characters-together/exercises
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
let num = 1001 ;
2
2
3
3
//Returns 'undefined'.
4
- console . log ( num . length ) ;
4
+ // console.log(num.length);
5
5
6
6
//Use type conversion to print the length (number of digits) of an integer.
7
7
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
+
9
10
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 ) ;
10
14
//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
+
You can’t perform that action at this time.
0 commit comments