Skip to content

Commit 55d51b9

Browse files
Update explicit-and-implicit-conversion-in-javascript.js
I missed Part 2 the first time i read the assignment
1 parent 519a00c commit 55d51b9

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

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

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

2121

22-
let result = "5" - 2; /*This Covers implicit conversion cause JavaScript converts the string to a number for you.*/
22+
let result = "5" - 2; //Correct:*This Covers implicit conversion cause JavaScript converts the string to a number for you.*/
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false"); /*This is an edge case because non empty strings in java script are always true so even though it says false it is valid.*/
25+
let isValid = Boolean("false"); //Correct:*This is an edge case because non empty strings in java script are always true so even though it says false it is valid.*/
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

30-
let age = Number("25"); /*Wrapping this string with a number conversions so that on line 31 the types are the same. This would also be an explicit conversion.*/
31-
let totalAge = age + 5;
30+
let age = Number("25"); //Incorrect:*Wrapping this string with a number conversions so that on line 31 the types are the same. This would also be an explicit conversion.*/
31+
let totalAge = Number(age) + 5;
3232
console.log("Total Age: " + totalAge);
33+
34+
*/ Examples /*
35+
36+
let runs = "4"; // runs is a string
37+
let outs = 2; // outs is a number
38+
39+
let inningUpdate = runs - outs;
40+
console.log("Inning Update: " + inningUpdate);
41+
__________________________________________________________
42+
let errors = null;
43+
let totalErrors = errors + 1;
44+
console.log("Total Errors: " + totalErrors);
45+
__________________________________________________________
46+
47+
let battingAverageStr = "0.300";
48+
let battingAverage = Number(battingAverageStr);
49+
50+
console.log("Batting Average: " + battingAverage);
51+
52+
53+
54+
55+
56+
57+
58+

0 commit comments

Comments
 (0)