1
1
/*
2
2
3
- Objective:
4
- In this activity, you will reinforce the skill of creating and using variables
5
- while practicing best practices in variable naming conventions through a hands-on,
6
- interactive coding challenge.
7
-
8
- The code snippet below may include:
9
- - Ambiguous or incorrect variable names.
10
- - Missing variables that need to be created.
11
- - Scenarios that require the use of clear and descriptive variable names.
12
-
13
- You will:
14
- - Identify Issues: Review the provided code and identify any variable names that:
15
- - Are unclear or too vague (e.g., a, b, c).
16
- - Do not follow best practices (e.g., camelCase, descriptive naming).
17
- - Refactor the Code: Rename the variables and rewrite the program using descriptive names that clearly convey the variable's purpose.
18
- - Enhance the Program: Add at least two additional variables to improve the program’s functionality or clarity.
19
-
20
- Things to reflect on:
21
- - Why is it important to use meaningful variable names?
22
- - What are the common pitfalls to avoid when naming variables?
23
- - How do clear variable names benefit team collaboration?
24
-
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
+
25
19
*/
26
20
27
- let name = "Alice" ;
28
- let itemType = "steaks" ;
29
- let amountOfItems = 5 ;
30
- let price = 20 ;
31
- let store = "the grocery store" ;
32
- let shoppingTrip = ( name + " bought " + amountOfItems + " " + itemType + " for $" + price + " at " + store + "." ) ;
33
21
34
- console . log ( shoppingTrip ) ;
22
+ let result = Number ( "5" ) - 2 ; //made 5 a number since it was already doing a subtraction.
23
+ console . log ( "The result is: " + result ) ;
24
+
25
+ let isValid = Boolean ( "false" ) ;
26
+ if ( isValid ) {
27
+ console . log ( Boolean ( false ) ) ; // made boolean false in console.log to get is valid to be false
28
+ }
29
+
30
+ let age = Number ( "25" ) ; // made 25 a number so that total agae would be 25 plus 5 to be 30 instead of 255.
31
+ let totalAge = age + 5 ;
32
+ console . log ( "Total Age: " + totalAge ) ;
0 commit comments