parent
0e8863cc4b
commit
f44e5814a7
@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>30DaysOfJavaScript: Day 03</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="background-color: black; color: white;">
|
||||||
|
<h1>30DaysOfJavaScript: Day 03</h1>
|
||||||
|
<h2>Booleans, undefined, null, date object</h2>
|
||||||
|
|
||||||
|
<!-- import your scripts here -->
|
||||||
|
<script src="main.js"></script>
|
||||||
|
<script src="level2.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
<style>
|
||||||
|
button{
|
||||||
|
color: white;
|
||||||
|
background-color: black;
|
||||||
|
padding: 5px;
|
||||||
|
margin: 5px;
|
||||||
|
border-radius: 7px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<button onclick="triangleA()">Area of a triangle</button><br>
|
||||||
|
<button onclick="triangleP()">Perimeter of a triangle</button><br>
|
||||||
|
<button onclick="rectPA()">Perimeter and area of a rectangle</button><br>
|
||||||
|
<button onclick="circleA()">Area of a circle</button><br>
|
||||||
|
<button onclick="calcSlope()">Calculate slope</button><br>
|
||||||
|
<button onclick="weeklyEarning()">Calculate weekly earnings</button><br>
|
||||||
|
<button onclick="nameLength()">Is your name long ?</button><br>
|
||||||
|
<button onclick="compareNames()">Is your first name longer than your last name ?</button><br>
|
||||||
|
<button onclick="ageCompare()">Age compare</button><br>
|
||||||
|
<button onclick="canDrive()">Are you allowed to drive ?</button><br>
|
||||||
|
<button onclick="lifeLength()">How many seconds have you lived ?</button><br>
|
||||||
|
<button onclick="calendar()">What's the time?</button><br>
|
||||||
|
</html>
|
@ -0,0 +1,98 @@
|
|||||||
|
function triangleA() {
|
||||||
|
let base = prompt("Input the triangles base length:");
|
||||||
|
let height = prompt("Input the triangles base height:");
|
||||||
|
let area = 0.5 * base * height;
|
||||||
|
alert(`The area of the triangle is ${area}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function triangleP() {
|
||||||
|
let a = prompt("Enter the length of side a");
|
||||||
|
let b = prompt("Enter the length of side b");
|
||||||
|
let c = prompt("Enter the length of side c");
|
||||||
|
let p = parseInt(a) + parseInt(b) + parseInt(c);
|
||||||
|
alert(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rectPA() {
|
||||||
|
let width = parseInt(prompt("Enter the width of the rectangle."));
|
||||||
|
let height = parseInt(prompt("Enter the height of the rectangle."));
|
||||||
|
let p = 2 * (width + height);
|
||||||
|
let a = width * height;
|
||||||
|
alert(`The perimeter of the rectangle is ${p}\nThe area of the rectangle is ${a}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function circleA() {
|
||||||
|
const PI = 3.14;
|
||||||
|
let r = parseInt(prompt("Enter the radius of the circle."));
|
||||||
|
let a = PI * (r * r);
|
||||||
|
alert(`The area of the circle is ${a}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcSlope() {
|
||||||
|
let x1 = parseInt(prompt("Enter the x position of the first point."));
|
||||||
|
let y1 = parseInt(prompt("Enter the y postiion of the first point"));
|
||||||
|
let x2 = parseInt(prompt("Enter the x postiion of the second point"));
|
||||||
|
let y2 = parseInt(prompt("Enter the y postiion of the second point"));
|
||||||
|
let m = (y2-y1)/(x2-x1);
|
||||||
|
alert(`The slope between points (${x1},${y1}) and (${x2},${y2}) is ${m}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function weeklyEarning() {
|
||||||
|
let h = parseInt(prompt("Enter hours"));
|
||||||
|
let rate = parseInt(prompt("Enter rate"));
|
||||||
|
let earning = h * rate;
|
||||||
|
alert(`Your weekly earning is ${earning}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function nameLength() {
|
||||||
|
let name = prompt("Enter your name")
|
||||||
|
if (name.length > 7){
|
||||||
|
alert("Your name is long!")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert("Your name is short!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareNames() {
|
||||||
|
let firstName = prompt("Enter your first name.")
|
||||||
|
let lastName = prompt("Enter your last name.")
|
||||||
|
if (firstName.length > lastName){
|
||||||
|
alert(`Your first name, ${firstName} is longer than your family name, ${lastName}`)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert(`Your first name, ${firstName} is not longer than your family name, ${lastName}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ageCompare() {
|
||||||
|
let myAge = 250;
|
||||||
|
let yourAge = 25;
|
||||||
|
alert(`I am ${myAge - yourAge} years older than you.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function canDrive() {
|
||||||
|
let age = parseInt(prompt("Enter birth year."));
|
||||||
|
if (age > 18){
|
||||||
|
alert(`You are ${age}. You are old enough to drive.`);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
alert(`You are ${age}. You will be allowed to drive after ${18 - age} years.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function lifeLength() {
|
||||||
|
let age = parseInt(prompt("Enter the number of years you have lived"));
|
||||||
|
let sec = age * 365 * 24 * 60 * 60;
|
||||||
|
alert(`You have lived ${sec} seconds.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function calendar() {
|
||||||
|
const now = new Date();
|
||||||
|
const currentYear = now.getFullYear();
|
||||||
|
const month = now.getMonth() + 1;
|
||||||
|
const date = now.getDate();
|
||||||
|
const hours = now.getHours();
|
||||||
|
const minutes = now.getMinutes();
|
||||||
|
alert(`${currentYear}-${month}-${day} ${hours}:${minutes}`)
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
let firstName = "Eligijus"
|
||||||
|
let lastName = "Dzikavicius"
|
||||||
|
let country = "Lithuania"
|
||||||
|
let city = "Kupiskis"
|
||||||
|
let age = "17"
|
||||||
|
let isMarried = false
|
||||||
|
let year = "2023"
|
||||||
|
|
||||||
|
console.log(parseInt("10"))
|
||||||
|
console.log(parseInt("9.8"))
|
||||||
|
|
||||||
|
let truthy1 = 12 // truthy
|
||||||
|
let truthy2 = "string" // truthy
|
||||||
|
let truthy3 = true // truthy
|
||||||
|
|
||||||
|
let falsy1 = 0 // falsy
|
||||||
|
let falsy2 = "" // falsy
|
||||||
|
let falsy3 = null // falsy
|
||||||
|
|
||||||
|
console.log(4 > 3) // true
|
||||||
|
console.log(4 >= 3) // true
|
||||||
|
console.log(4 < 3) // false
|
||||||
|
console.log(4 <= 3) // false
|
||||||
|
console.log(4 == 4) // true
|
||||||
|
console.log(4 === 4) // true
|
||||||
|
console.log(4 != 4) // false
|
||||||
|
console.log(4 !== 4) // false
|
||||||
|
console.log(4 != '4') // false
|
||||||
|
console.log(4 == '4') // true
|
||||||
|
console.log(4 === '4') // false
|
||||||
|
console.log("python".length != "jargon".length) // false
|
||||||
|
// All correct !
|
||||||
|
|
||||||
|
const now = new Date()
|
||||||
|
const currentYear = now.getFullYear()
|
||||||
|
const month = now.getMonth() + 1
|
||||||
|
const date = now.getDate()
|
||||||
|
const day = now.getDay() + 1
|
||||||
|
const hours = now.getHours()
|
||||||
|
const minutes = now.getMinutes()
|
||||||
|
const seconds = now.getSeconds()
|
||||||
|
const allTime = now.getTime()
|
||||||
|
|
||||||
|
console.log(`The current year is ${currentYear}`)
|
||||||
|
console.log(`The current month is ${month}`)
|
||||||
|
console.log(`The current date is ${date}`)
|
||||||
|
console.log(`The current day of the week is ${day}`)
|
||||||
|
console.log(`The current time is ${hours}:${minutes}:${seconds}`)
|
||||||
|
console.log(`The amount of seconds passed since Jan 1, 1970 is ${allTime}`)
|
Loading…
Reference in new issue