File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,28 @@ Use console.log() to clearly show the before-and-after type conversions.
19
19
*/
20
20
21
21
22
- let result = "5" - 2 ;
23
- console . log ( "The result is: " + result ) ;
22
+ let result = Number ( "5" ) - 2 ; //this code works correctly as is, but I can also convert the string to a numeric value
23
+ console . log ( "The result is: " + result ) ; //displays 3
24
24
25
- let isValid = Boolean ( "false" ) ;
25
+
26
+ let isValid = false ; //previously had a string of the word false using Boolean() but was still considered truthy due to if(INPUT)
26
27
if ( isValid ) {
27
- console . log ( "This is valid!" ) ;
28
+ console . log ( "This is valid!" ) ; //does not display
29
+ } else { //added else to display if value is intentionally false
30
+ console . log ( "This is invalid" ) //displays This is invalid
28
31
}
29
32
30
- let age = "25" ;
33
+
34
+ let age = Number ( "25" ) ; //this avoids concatenation by converting string to number
31
35
let totalAge = age + 5 ;
32
36
console . log ( "Total Age: " + totalAge ) ;
37
+
38
+
39
+ let loginPass ;
40
+ if ( loginPass ) ; //this is marked as undefined, but since there is an entry here it results in truthy
41
+ console . log ( "Access Granted" ) ;
42
+
43
+
44
+ let groupId = 55400 ; //if these remain number values, the + will erroneously add the values together
45
+ let policyNumber = 2626801 ;
46
+ console . log ( "Member ID: " + String ( groupId ) + String ( policyNumber ) ) ; //Displays Member ID: 554002626801
You can’t perform that action at this time.
0 commit comments