Skip to content

Commit af01271

Browse files
committed
fixed errors using explicit type conversion methods and added my own examples of type conversion methods
1 parent ce92942 commit af01271

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ Use console.log() to clearly show the before-and-after type conversions.
1919
*/
2020

2121

22-
let result = "5" - 2;
22+
let result = "5" - 2; // implicit type conversion didn't need fixed
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false");
25+
let isValid = Boolean(false); // removed quotation from "false" changing it from a String to a falsey Boolean
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

30-
let age = "25";
31-
let totalAge = age + 5;
30+
let age = "25"; // added Number() to age variable converting it from a String to a Number
31+
let totalAge = Number(age) + 5;
3232
console.log("Total Age: " + totalAge);
33+
34+
let hardcoverBookCost = 38;
35+
let paperbackBookCost = 15;
36+
console.log(`A hardcover book costs $${hardcoverBookCost} but the paperback only costs $${paperbackBookCost}.`);
37+
38+
let answer = true;
39+
console.log(answer.toString());
40+

0 commit comments

Comments
 (0)