diff --git a/explicit-and-implicit-conversion-in-javascript.js b/explicit-and-implicit-conversion-in-javascript.js index ede0ccd..4a646a9 100644 --- a/explicit-and-implicit-conversion-in-javascript.js +++ b/explicit-and-implicit-conversion-in-javascript.js @@ -1,24 +1,3 @@ -/* - -Part 1: Debugging Challenge -The JavaScript code below contains intentional bugs related to type conversion. -Please do the following: - - Run the script to observe unexpected outputs. - - Debug and fix the errors using explicit type conversion methods like Number() , String() , or Boolean() where necessary. - - Annotate the code with comments explaining why the fix works. - -Part 2: Write Your Own Examples -Write their own code that demonstrates: - - One example of implicit type conversion. - - One example of explicit type conversion. - - *We encourage you to: -Include at least one edge case, like NaN, undefined, or null . -Use console.log() to clearly show the before-and-after type conversions. - -*/ - - let result = "5" - 2; console.log("The result is: " + result); @@ -28,5 +7,12 @@ if (isValid) { } let age = "25"; -let totalAge = age + 5; -console.log("Total Age: " + totalAge); +let totalAge = (Number(age)) + 5; // added Number() to age to make it a number rather than a string so it would actually add 25 and 5 rather than just outputting 255 +console.log("Total Age: " + totalAge); + + +let guests; +console.log(Boolean(guests)) // this is my example of an explicit type conversion as well as my use of an edge case, undefined. + + +console.log("153" - 53); // this is my example of an implicit type conversion \ No newline at end of file