Skip to content

Commit 823b277

Browse files
committed
Updates made per assignment instructions
1 parent ce92942 commit 823b277

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ Use console.log() to clearly show the before-and-after type conversions.
2020

2121

2222
let result = "5" - 2;
23-
console.log("The result is: " + result);
23+
console.log("The result is: " + result); // This code is fine as is. Implicit converstion changes the "5" string into a number and the equation can be solved.
2424

25-
let isValid = Boolean("false");
25+
let isValid = (false); // Removed "" from false as any non empty string is truthy. Also removed the Boolean conversion as it is redundant after removing the "". False is always falsy. This makes the "if" false as it is supposed to be
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

3030
let age = "25";
31-
let totalAge = age + 5;
31+
let totalAge = Number(age) + 5; // Added the Number() conversion to change "25" from a string to a number. This allows the console.log to complete the addition equation.
3232
console.log("Total Age: " + totalAge);
33+
34+
let area = "2" * 4;
35+
console.log("The area of the board is " + area); // Multiplication is safe to use with implicit conversion. The "2" is a string but it converted into a number in order to complete the console.log equation.
36+
37+
let length = "Seventy";
38+
let width = Number(length);
39+
console.log(width); // The Number() explicit converion is used to change the value of length from a string and into a number. However, "Seventy" is not a number, so the console.log outputs NaN.

0 commit comments

Comments
 (0)