Skip to content

Commit 31543c8

Browse files
Hope this works, added examples for homework
1 parent ce92942 commit 31543c8

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
/*
2-
3-
Part 1: Debugging Challenge
4-
The JavaScript code below contains intentional bugs related to type conversion.
5-
Please do the following:
6-
- Run the script to observe unexpected outputs.
7-
- Debug and fix the errors using explicit type conversion methods like Number() , String() , or Boolean() where necessary.
8-
- Annotate the code with comments explaining why the fix works.
9-
10-
Part 2: Write Your Own Examples
11-
Write their own code that demonstrates:
12-
- One example of implicit type conversion.
13-
- One example of explicit type conversion.
14-
15-
*We encourage you to:
16-
Include at least one edge case, like NaN, undefined, or null .
17-
Use console.log() to clearly show the before-and-after type conversions.
18-
19-
*/
20-
21-
221
let result = "5" - 2;
232
console.log("The result is: " + result);
243

@@ -27,6 +6,12 @@ if (isValid) {
276
console.log("This is valid!");
287
}
298

30-
let age = "25";
9+
let age = Number("25"); //The Number() here changes the string value into a number value so that when it is used later for total age it does not convert it to a string
3110
let totalAge = age + 5;
32-
console.log("Total Age: " + totalAge);
11+
console.log(totalAge);
12+
13+
let explicit = undefined;
14+
let explicitConversion = String(explicit);
15+
console.log(explicitConversion);
16+
17+
console.log("10" * "10");

0 commit comments

Comments
 (0)