parent
a5ee9cc138
commit
b295591ef6
@ -0,0 +1,135 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<button id="drive-condition">Calculate drive condition</button>
|
||||
<button id="age-comparition">Compare age</button>
|
||||
<button id="grades-calculate">Calculate grades</button>
|
||||
<button id="season">Find season</button>
|
||||
<script>
|
||||
|
||||
// Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he needs to turn 18.
|
||||
|
||||
// Enter your age: 30
|
||||
// You are old enough to drive.
|
||||
|
||||
// Enter your age:15
|
||||
// You are left with 3 years to drive.
|
||||
let btnCalDriveAge = document.getElementById("drive-condition");
|
||||
btnCalDriveAge.onclick = function(){calDriveAge()}
|
||||
|
||||
function calDriveAge(){
|
||||
let age = parseInt(prompt("Enter your age:"));
|
||||
|
||||
if (age >= 18){
|
||||
confirm(`You are left ${age} enough to drive`)
|
||||
} else if (age >= 1){
|
||||
confirm(`You are ${18 - age} years to drive`)
|
||||
} else {
|
||||
confirm("Please enter incorrect age")
|
||||
}
|
||||
}
|
||||
|
||||
// Compare the values of myAge and yourAge using if … else. Based on the comparison and log the result to console stating who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.
|
||||
|
||||
// Enter your age: 30
|
||||
// You are 5 years older than me.
|
||||
|
||||
let btnAgeCmp = document.getElementById("age-comparition");
|
||||
btnAgeCmp.onclick = function(){cmpAge()}
|
||||
|
||||
function cmpAge(){
|
||||
let now = new Date
|
||||
let myAge = now.getFullYear() - 2000
|
||||
let yourAge = parseInt(prompt("Enter your age"))
|
||||
let subAge = yourAge - myAge
|
||||
|
||||
if (yourAge <= 0){
|
||||
confirm("You need enter correct age")
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAge < 0) {
|
||||
confirm(`You are ${Math.abs(subAge)} younger than me`)
|
||||
} else {
|
||||
confirm(`You are ${Math.abs(subAge)} older than me`)
|
||||
}
|
||||
}
|
||||
|
||||
// Write a code which can give grades to students according to theirs scores:
|
||||
// 80-100, A
|
||||
// 70-89, B
|
||||
// 60-69, C
|
||||
// 50-59, D
|
||||
// 0-49, F
|
||||
let btnGradesCal = document.getElementById("grades-calculate");
|
||||
btnGradesCal.onclick = function(){calGrades()}
|
||||
|
||||
function calGrades(){
|
||||
let yourScore = parseInt(prompt("Enter your score"))
|
||||
|
||||
switch (true){
|
||||
case (yourScore <= 100 && yourScore >= 80):
|
||||
confirm("You are A")
|
||||
break
|
||||
case (yourScore < 90 && yourScore >= 70):
|
||||
confirm("You are B")
|
||||
break
|
||||
case (yourScore < 70 && yourScore >= 60):
|
||||
confirm("You are C")
|
||||
break
|
||||
case (yourScore < 60 && yourScore >= 50):
|
||||
confirm("You are D")
|
||||
break
|
||||
case (yourScore < 50 && yourScore >= 0):
|
||||
confirm("You are F")
|
||||
break
|
||||
default:
|
||||
confirm("You need enter correct score")
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the season is Autumn, Winter, Spring or Summer. If the user input is :
|
||||
// September, October or November, the season is Autumn.
|
||||
// December, January or February, the season is Winter.
|
||||
// March, April or May, the season is Spring
|
||||
// June, July or August, the season is Summer
|
||||
let btnSeason = document.getElementById("season");
|
||||
btnSeason.onclick = function(){findSeason()}
|
||||
|
||||
function findSeason(){
|
||||
let autumn = ["September", "October", "November"]
|
||||
let winter = ["December", "January", "February"]
|
||||
let spring = ["March", "April", "May"]
|
||||
let summer = ["June", "July", "August"]
|
||||
|
||||
let month = prompt("Enter month:(letter)")
|
||||
month = month.toLowerCase().charAt(0).toUpperCase() + month.slice(1)
|
||||
console.log(month)
|
||||
|
||||
switch (true){
|
||||
case autumn.includes(month):
|
||||
confirm("It's autumn")
|
||||
break
|
||||
case winter.includes(month):
|
||||
confirm("It's winter")
|
||||
break
|
||||
case spring.includes(month):
|
||||
confirm("It's spring")
|
||||
break
|
||||
case summer.includes(month):
|
||||
confirm("It's summer")
|
||||
break
|
||||
default:
|
||||
confirm("Please enter correct month")
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue