-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathvariables-naming-conventions-and-top-to-bottom-code-evaluation.js
More file actions
40 lines (33 loc) · 1.94 KB
/
variables-naming-conventions-and-top-to-bottom-code-evaluation.js
File metadata and controls
40 lines (33 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Objective:
In this activity, you will reinforce the skill of creating and using variables
while practicing best practices in variable naming conventions through a hands-on,
interactive coding challenge.
The code snippet below may include:
- Ambiguous or incorrect variable names.
- Missing variables that need to be created.
- Scenarios that require the use of clear and descriptive variable names.
You will:
- Identify Issues: Review the provided code and identify any variable names that:
- Are unclear or too vague (e.g., a, b, c).
- Do not follow best practices (e.g., camelCase, descriptive naming).
- Refactor the Code: Rename the variables and rewrite the program using descriptive names that clearly convey the variable's purpose.
- Enhance the Program: Add at least two additional variables to improve the program’s functionality or clarity.
Things to reflect on:
- Why is it important to use meaningful variable names?
- What are the common pitfalls to avoid when naming variables?
- How do clear variable names benefit team collaboration?
*/
/*let a = "Alice"; //vague variable name, not using camelCase
let b = 5; //vague variable name, not using camelCase
let c = 20; //vague variable name, not using camelCase
let d = a + " bought " + b + " items for $" + c + "."; //vague variable name, not using camelCase
console.log(d);
*/
let userName = "Alice"; //previously had vague variable name, not using camelCase
let numberOfItems = 5; //previously had vague variable name, not using camelCase
let totalCost = 20; //previously had vague variable name, not using camelCase
let itemsBought = userName + " bought " + numberOfItems + " items for $" + totalCost + "."; //previously had vague variable name, not using camelCase
let programDescription = "This program calculates the total cost of items bought by a user."; //added additional variable to improve program's functionality
console.log(itemsBought);
console.log(programDescription);