parent
11fda60bb9
commit
8ad787242b
@ -0,0 +1,13 @@
|
||||
<!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>Level 1 Exercise</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script src="./level1.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 1. 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.
|
||||
*
|
||||
*/
|
||||
let age = Number(prompt('Enter your age: '))
|
||||
|
||||
if (age >= 18) {
|
||||
console.log('You are old enough to drive.')
|
||||
} else {
|
||||
console.log(`You are left with ${18 - age} years to drive.`)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 2. 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.
|
||||
*/
|
||||
let yourAge = Number(prompt('Enter your age: '))
|
||||
let myAge = 21
|
||||
|
||||
if (yourAge > myAge) {
|
||||
console.log(`You are ${yourAge - myAge} years older than me.`)
|
||||
} else {
|
||||
console.log(`I'm ${myAge - yourAge} years older than you`)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 3. If a is greater than b return 'a is greater than b' else
|
||||
* 'a is less than b'. Try to implement it in two ways
|
||||
*/
|
||||
let a = 4
|
||||
let b = 3
|
||||
|
||||
a > b
|
||||
? console.log(`${a} is greater than ${b}`)
|
||||
: console.log(`${b} is greater than ${a}`)
|
||||
|
||||
|
||||
/**
|
||||
* 4. Even numbers are divisible by 2 and the remainder is zero. How do you check,
|
||||
* if a number is even or not using JavaScript?
|
||||
*/
|
||||
let number = Number(prompt('Enter a number: '))
|
||||
|
||||
if (number % 2 == 0) {
|
||||
console.log(`${number} is an even number.`)
|
||||
} else {
|
||||
console.log(`${number} is an odd number.`)
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<!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>Level 2 Exercises</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script src="./level2.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 1. 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 score = Number(prompt('Enter your score: '))
|
||||
|
||||
switch (true) {
|
||||
case 80 <= score && score <= 100:
|
||||
console.log('A')
|
||||
break
|
||||
case 70 <= score && score <= 79:
|
||||
console.log('B')
|
||||
break
|
||||
case 60 <= score && score <= 69:
|
||||
console.log('C')
|
||||
break
|
||||
case 50 <= score && score <= 59:
|
||||
console.log('D')
|
||||
break
|
||||
case 0 <= score && score <= 49:
|
||||
console.log('F')
|
||||
break
|
||||
default:
|
||||
console.log('Number invalid')
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. 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 season = prompt('Whats is the month? ')
|
||||
|
||||
let Autumn = ['September', 'October', 'November']
|
||||
let Winter = ['December', 'January', 'February']
|
||||
let Spring = ['March', 'April', 'May']
|
||||
let Summer = ['June', 'July', 'August']
|
||||
|
||||
switch (true) {
|
||||
case Autumn.includes(season):
|
||||
console.log('The season is Autumn')
|
||||
break
|
||||
case Winter.includes(season):
|
||||
console.log('The season is Winter')
|
||||
break
|
||||
case Spring.includes(season):
|
||||
console.log('The season is Spring')
|
||||
break
|
||||
case Summer.includes(season):
|
||||
console.log('The season is Summer')
|
||||
break
|
||||
default:
|
||||
console.log('Season invalid')
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 3. Check if a day is weekend day or a working day. Your script will
|
||||
* take day as an input.
|
||||
*/
|
||||
let day = prompt('Whats is the day today? ')
|
||||
let newDay = day[0].toUpperCase()+day.slice(1, day.length).toLowerCase()
|
||||
|
||||
let dayWork = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
|
||||
let weekend = ['Saturday', 'Sunday']
|
||||
|
||||
switch (true) {
|
||||
case dayWork.includes(newDay):
|
||||
console.log(`${newDay} is a working day.`)
|
||||
break
|
||||
case weekend.includes(newDay):
|
||||
console.log(`${newDay} is a weekend.`)
|
||||
break
|
||||
default:
|
||||
console.log('Day invalid')
|
||||
}
|
Loading…
Reference in new issue