-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.js
More file actions
39 lines (30 loc) · 1.3 KB
/
example2.js
File metadata and controls
39 lines (30 loc) · 1.3 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
/**
* Description: This program is assigning student IDs to 5 new students but there is a bug in the code preventing the code to run
* as expected. Your task is to run and debug the program using breakpoints.
*
* TODO: The program has error message in the console. You should read the message and debug accordingly. The final
* goal is to print out a student ID for each student to the console. The ID numbers should be from 0 to 4.
*/
function checkPoint2(){
alert3();
const friends = ["Rei", "Miya", "Alexis", "Ethan", "Anna"];
const studentID = [];
// Fixed the declaration of i using let instead of const
for (let i = 0; i < friends.length; i++){
studentID.push("JS" + i);
}
console.log(studentID);
alerts(studentID);
}
/************************************************ DON'T EDIT THE CODE BELOW ******************************************************/
function alert3() {
alert("All students need to get their student IDs, but it seems like the system is down. Can you help debug the system? Go to the example2.js file and work on checkpoint 2.");
}
function alerts(studentID) {
if (studentID.length == 5) {
alert("Yay! You got the system running!");
}
else {
alert("Hmmm! It seems like Rei hasn't received his ID. Keep debugging!");
}
}