commit
a8ed2f185c
@ -0,0 +1,80 @@
|
|||||||
|
<!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>
|
||||||
|
<script>
|
||||||
|
let [firstName, lastName, country, city, age, isMarried, year] = ["hoang", "tran", "viet nam", 22, true, 2022]
|
||||||
|
console.log(firstName, lastName, country, city, age, isMarried, year)
|
||||||
|
console.log(typeof(firstName), typeof(lastName), typeof(country), typeof(city), typeof(age), typeof(isMarried), typeof(year))
|
||||||
|
|
||||||
|
console.log("Check if type of '10' is equal to 10", '10' === "10")
|
||||||
|
|
||||||
|
console.log("Check if parseInt('9.8') is equal to 10:", parseInt('9.8') == 10)
|
||||||
|
|
||||||
|
console.log("Boolean value is either true or false:", typeof(true), typeof(false))
|
||||||
|
|
||||||
|
if(1){
|
||||||
|
if("1"){
|
||||||
|
if(true){
|
||||||
|
console.log("truthy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!0){
|
||||||
|
if(!NaN){
|
||||||
|
if(!undefined){
|
||||||
|
if(!false){
|
||||||
|
if(!""){
|
||||||
|
if(!0n){
|
||||||
|
console.log("falsy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4 > 3 true
|
||||||
|
// 4 >= 3 true
|
||||||
|
// 4 < 3 false
|
||||||
|
// 4 <= 3 false
|
||||||
|
// 4 == 4 true
|
||||||
|
// 4 === 4 true
|
||||||
|
// 4 != 4 false
|
||||||
|
// 4 !== 4 false
|
||||||
|
// 4 != '4' true
|
||||||
|
// 4 == '4' true
|
||||||
|
// 4 === '4' false
|
||||||
|
|
||||||
|
console.log(`Find the length of python ${"python".length} and jargon ${"jargon".length} and make a falsy comparison statement: `, "python".length > "jargon".length)
|
||||||
|
|
||||||
|
// 4 > 3 && 10 < 12 f
|
||||||
|
// 4 > 3 && 10 > 12 f
|
||||||
|
// 4 > 3 || 10 < 12 t
|
||||||
|
// 4 > 3 || 10 > 12 t
|
||||||
|
// !(4 > 3) f
|
||||||
|
// !(4 < 3) t
|
||||||
|
// !(false) t
|
||||||
|
// !(4 > 3 && 10 < 12) t
|
||||||
|
// !(4 > 3 && 10 > 12) t
|
||||||
|
// !(4 === '4') t
|
||||||
|
// There is no 'on' in both dragon and python
|
||||||
|
let now = new Date();
|
||||||
|
|
||||||
|
console.log("What is the year today?", now.getFullYear())
|
||||||
|
console.log("What is the month today as a number?", now.getMonth() + 1)
|
||||||
|
console.log("What is the date today?", now.getDate())
|
||||||
|
console.log("What is the day today as a number?", now.getDay())
|
||||||
|
console.log("What is the hours now?", now.getHours())
|
||||||
|
console.log("What is the minutes now?", now.getMinutes())
|
||||||
|
console.log("Find out the numbers of seconds elapsed from January 1, 1970 to now.", now.getTime())
|
||||||
|
//
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,39 @@
|
|||||||
|
<!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="tri-area">Calculate triangle area</button>
|
||||||
|
<button id="time-now">Display time</button>
|
||||||
|
<script>
|
||||||
|
let triArea = document.getElementById("tri-area")
|
||||||
|
triArea.onclick = function(){calTriangleArea()}
|
||||||
|
function calTriangleArea(){
|
||||||
|
let base = parseFloat(prompt("enter base of triangle"))
|
||||||
|
let height = parseFloat(prompt("enter height of triangle"))
|
||||||
|
let area = base*height*0.5
|
||||||
|
alert(`area of a triangle ${area}`)
|
||||||
|
console.log("calTriangleArea executed")
|
||||||
|
return area
|
||||||
|
}
|
||||||
|
|
||||||
|
let timeNow = document.getElementById("time-now")
|
||||||
|
|
||||||
|
function convertMiutesMiliseconds(time){
|
||||||
|
time < 10 ? time = `0${time}` : time
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
|
||||||
|
timeNow.onclick = function(){displayTimeNow()}
|
||||||
|
function displayTimeNow(){
|
||||||
|
let now = new Date()
|
||||||
|
let readableTime = `This is ${now.getHours()}:${convertMiutesMiliseconds(now.getMinutes())}:${convertMiutesMiliseconds(now.getSeconds())}`
|
||||||
|
confirm(readableTime)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -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