Variables
We can declare variables in three ways
1. var (function scoped)
2. let (block scoped)
3. const (block scoped)
Functions and loops
1
2
3
4
5
6
7
8
9
10
| // Function to print student result
function PrintResult(rollNum) {
alert("Username with roll number " + rollNum + " has passed the exam");
// any other logic to the display result
}
for (let i = 0; i < 100; i++) {
PrintResult(rollNumbers[i]); // this will be called 100 times
}
|
If condition
1
2
3
4
5
6
| age = prompt("What is your age")
if (age >= 18) {
document.getElementById("message").innerHTML = "You are an adult.";
} else {
document.getElementById("message").innerHTML = "You are a minor.";
}
|