forked from iDTech-Neha/iDTech_JavaScript_Coding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.js
More file actions
42 lines (35 loc) · 1.54 KB
/
Copy pathexample2.js
File metadata and controls
42 lines (35 loc) · 1.54 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
41
42
/**
* 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();
// TODO: Remove the bugs from the code below.
//Change two instances of const to let. A const variable
//cannot be changed after it is initialized.
const friends = ["Rei", "Miya", "Alexis", "Ethan", "Anna"];
let studentID = [];
//Set i to 0 instead of 1. The first index of an array is 0
//so i needs to be initialized to 0.
for (let i = 0; i < friends.length; i++){
studentID.push("JSMIT" + i);
}
console.log(studentID);
// DO NOT CHANGE THE CODE BELOW
alerts(studentID);
}
/************************************************ DONT CHANGE 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!");
}
}