<!DOCTYPE html>
<html>
<body>
<script>
let age = 20;
if(age >= 18) {
console.log("Eligible for Vote");
document.write("Eligible for Vote");
}
</script>
</body>
</html>
Eligible for Vote
<!DOCTYPE html>
<html>
<body>
<script>
let num = 7;
if(num % 2 == 0) {
console.log("Even Number");
document.write("Even Number");
}
else {
console.log("Odd Number");
document.write("Odd Number");
}
</script>
</body>
</html>
Odd Number
<!DOCTYPE html>
<html>
<body>
<script>
let marks = 75;
if(marks >= 90) {
console.log("Grade A");
document.write("Grade A");
}
else if(marks >= 60) {
console.log("Grade B");
document.write("Grade B");
}
else if(marks >= 40) {
console.log("Grade C");
document.write("Grade C");
}
else {
console.log("Fail");
document.write("Fail");
}
</script>
</body>
</html>
Grade B
<!DOCTYPE html>
<html>
<head>
<title>Traffic Signal Program</title>
</head>
<body>
<h2>Traffic Signal Check Using Switch Statement</h2>
<script>
// Variable declaration
let color = "red";
// Switch statement
switch(color) {
case "red":
console.log("Stop");
document.write("Stop");
break;
case "yellow":
console.log("Wait");
document.write("Wait");
break;
case "green":
console.log("Go");
document.write("Go");
break;
default:
console.log("Invalid Color");
document.write("Invalid Color");
}
</script>
</body>
</html>
Stop
<!DOCTYPE html>
<html>
<body>
<script>
let age = 20;
let hasID = true;
if(age >= 18) {
if(hasID == true) {
console.log("Eligible for License");
document.write("Eligible for License");
}
else {
console.log("ID Required");
document.write("ID Required");
}
}
else {
console.log("Not Eligible");
document.write("Not Eligible");
}
</script>
</body>
</html>
Eligible for License
<!DOCTYPE html>
<html>
<body>
<script>
let age = Number(prompt("Enter your age:"));
let hasLicense = prompt("Do you have a driving license? (yes/no)") == "yes";
let isDrunk = prompt("Are you drunk? (yes/no)") == "yes";
if (age >= 18 && hasLicense && !isDrunk)
{
console.log("You can drive safely.");
document.write("You can drive safely.");
}
else
{
console.log("You cannot drive.");
document.write("You cannot drive.");
}
</script>
</body>
</html>