Skip to content

Commit 9632650

Browse files
committed
//3/12/25
1 parent ce92942 commit 9632650

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

explicit-and-implicit-conversion-in-javascript.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,41 @@ Use console.log() to clearly show the before-and-after type conversions.
1818
1919
*/
2020

21+
//Part 1
2122

2223
let result = "5" - 2;
2324
console.log("The result is: " + result);
2425

25-
let isValid = Boolean("false");
26+
/*
27+
This is correct and reguired no change.
28+
*/
29+
30+
let isValid = Boolean("true");
2631
if (isValid) {
2732
console.log("This is valid!");
2833
}
2934

35+
/*
36+
isValid is a truthy, so it needed to be changed to "true".
37+
*/
38+
3039
let age = "25";
31-
let totalAge = age + 5;
40+
let totalAge = (Number(age) + 5);
3241
console.log("Total Age: " + totalAge);
42+
43+
/*
44+
The variable age needed to be converted to a number from a string at line 39, so the numbers are added.
45+
*/
46+
47+
// Part 2
48+
let currentYear = "2025";
49+
let birthYear = "1992";
50+
let myAge = (Number(currentYear) - Number(birthYear));
51+
52+
console.log('You are ' + (myAge) + ' years old.');
53+
54+
let bool1 = false;
55+
let num1 = null;
56+
bool1 == num1;
57+
58+
console.log(num1 + bool1)

0 commit comments

Comments
 (0)