parent
99efa7fe67
commit
478521188f
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>30DaysOfJavaScript: Day 04</title>
|
||||
</head>
|
||||
|
||||
<body style="background-color: black; color: white;">
|
||||
<style>
|
||||
button{
|
||||
color: white;
|
||||
background-color: black;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
</style>
|
||||
<h1>30DaysOfJavaScript: Day 04</h1>
|
||||
<h2>Conditionals</h2>
|
||||
|
||||
<script src="main.js"></script>
|
||||
<button onclick="canDrive()">Are you old enough to drive ?</button><br>
|
||||
<button onclick="isOlder()">Are you older than me ?</button><br>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -0,0 +1,40 @@
|
||||
function canDrive() {
|
||||
let age = parseInt(prompt("Enter your age."));
|
||||
|
||||
if (age < 18) {
|
||||
alert("You are not old enough to drive");
|
||||
}
|
||||
else {
|
||||
alert("You are old enough to drive!")
|
||||
}
|
||||
}
|
||||
|
||||
function isOlder() {
|
||||
let myAge = 17;
|
||||
let yourAge = parseInt(prompt("How old are you ?"));
|
||||
|
||||
if (yourAge > myAge) {
|
||||
alert(`You are ${yourAge - myAge} year(s) older than me.`)
|
||||
}
|
||||
else {
|
||||
alert(`I am ${myAge - yourAge} years older than you!`)
|
||||
}
|
||||
}
|
||||
|
||||
let a = 4;
|
||||
let b = 3;
|
||||
|
||||
if (a > b) {
|
||||
console.log(`${a} is greater than ${b}`);
|
||||
}
|
||||
else{
|
||||
console.log(`${a} is less than ${b}`);
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case (a > b):
|
||||
console.log(`${a} is greater than ${b}`);
|
||||
break;
|
||||
default:
|
||||
console.log(`${a} is less than ${b}`);
|
||||
}
|
||||
Loading…
Reference in new issue