From 823b2773b71e94f79b99e77111ec8719f41c00d6 Mon Sep 17 00:00:00 2001 From: Choffman Date: Tue, 11 Mar 2025 19:13:19 -0500 Subject: [PATCH] Updates made per assignment instructions --- explicit-and-implicit-conversion-in-javascript.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/explicit-and-implicit-conversion-in-javascript.js b/explicit-and-implicit-conversion-in-javascript.js index ede0ccd..e28819e 100644 --- a/explicit-and-implicit-conversion-in-javascript.js +++ b/explicit-and-implicit-conversion-in-javascript.js @@ -20,13 +20,20 @@ Use console.log() to clearly show the before-and-after type conversions. let result = "5" - 2; -console.log("The result is: " + result); +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. -let isValid = Boolean("false"); +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 if (isValid) { console.log("This is valid!"); } let age = "25"; -let totalAge = age + 5; +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. console.log("Total Age: " + totalAge); + +let area = "2" * 4; +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. + +let length = "Seventy"; +let width = Number(length); +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. \ No newline at end of file