From 49c62c5f066eedfde27909775d5e4448f0fae9cf Mon Sep 17 00:00:00 2001 From: chrissy Date: Thu, 20 Mar 2025 11:50:12 -0500 Subject: [PATCH 1/2] Fixed and debugged prewritten code while adding own in Part 2 of assignment. --- ...t-and-implicit-conversion-in-javascript.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/explicit-and-implicit-conversion-in-javascript.js b/explicit-and-implicit-conversion-in-javascript.js index ede0ccd..e577df6 100644 --- a/explicit-and-implicit-conversion-in-javascript.js +++ b/explicit-and-implicit-conversion-in-javascript.js @@ -19,14 +19,37 @@ Use console.log() to clearly show the before-and-after type conversions. */ -let result = "5" - 2; +let result = Number("5") - 2; //this looked correct to me and displayed how I expected. I added Number() to be more clear console.log("The result is: " + result); -let isValid = Boolean("false"); +let isValid = Boolean("false" == false);//I added '==' so that the string 'false' will be equal to the boolean false. if (isValid) { console.log("This is valid!"); -} +} + let age = "25"; -let totalAge = age + 5; + +let totalAge = Number(age) + 5; //turned the variable 'age' from string to number so the equation can work console.log("Total Age: " + totalAge); + + +//Part Two + +//Implicit type conversion +let numofItems = 38; +console.log(`You have ${numofItems} items in your cart.`); //Template literal + +//Explicit Type Conversion +let str = "72"; +let num = Number(str); + +console.log(num); // converting to a number from string + +//One edge case + +let slicesofPizza = Boolean(null); //used null to for Boolean value and 'if()' to create output if returned true. If false, code shows the expected output. + if (slicesofPizza) { + console.log("There is currently no pizza!"); + } +console.log(slicesofPizza); From eb89d492ec495c59e245c3a260aab3bbb74dcd10 Mon Sep 17 00:00:00 2001 From: chrissy Date: Thu, 20 Mar 2025 12:30:33 -0500 Subject: [PATCH 2/2] modified my answer for the Boolean problem --- explicit-and-implicit-conversion-in-javascript.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/explicit-and-implicit-conversion-in-javascript.js b/explicit-and-implicit-conversion-in-javascript.js index e577df6..7a5e8bb 100644 --- a/explicit-and-implicit-conversion-in-javascript.js +++ b/explicit-and-implicit-conversion-in-javascript.js @@ -22,11 +22,11 @@ Use console.log() to clearly show the before-and-after type conversions. let result = Number("5") - 2; //this looked correct to me and displayed how I expected. I added Number() to be more clear console.log("The result is: " + result); -let isValid = Boolean("false" == false);//I added '==' so that the string 'false' will be equal to the boolean false. +let isValid = Boolean("false"); //originally fixed at (let isValid = Boolean ("false"==false));) if (isValid) { console.log("This is valid!"); } - +//After reading more about Boolean(), this is a "truthy" and that as long as there is something in the value of the Boolean() other than edge case. let age = "25";