-
-
Save smart-onion/133a29ea5516f950459e8d6e462ab0cb to your computer and use it in GitHub Desktop.
JS1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title></title> | |
<link rel="stylesheet" href="css/style.css"> | |
<meta name="description" content=""> | |
<meta property="og:title" content=""> | |
<meta property="og:type" content=""> | |
<meta property="og:url" content=""> | |
<meta property="og:image" content=""> | |
<meta property="og:image:alt" content=""> | |
<link rel="icon" href="/favicon.ico" sizes="any"> | |
<link rel="icon" href="/icon.svg" type="image/svg+xml"> | |
<link rel="apple-touch-icon" href="icon.png"> | |
<link rel="manifest" href="site.webmanifest"> | |
<meta name="theme-color" content="#fafafa"> | |
</head> | |
<body> | |
<!-- Add your site or application content here --> | |
<p>Hello world! This is HTML5 Boilerplate.</p> | |
<script src="js/app.js"></script> | |
<h5>Task 5</h5> | |
<label for="num1">Number 1</label> | |
<input id="num1" type="number" > | |
<label for="num2">Number 2</label> | |
<input id="num2" type="number" > | |
<button onclick="Add()">+</button> | |
<button onclick="Dedact()">-</button> | |
<button onclick="Multiply()">*</button> | |
<button onclick="Devide()">/</button> | |
<p id="result"></p> | |
</body> | |
<script> | |
// Task 1 | |
function task1() { | |
let num = prompt("Enter your number", 0); | |
num = Math.pow(Number(num), 2); | |
alert(num); | |
} | |
// Task 2 | |
function task2(){ | |
let num1 = prompt("Enter first number", 0); | |
let num2 = prompt("Enter second number", 0); | |
let result = (Number(num1) +Number(num2)) / 2; | |
alert(result); | |
} | |
// Task 3 | |
function task3(){ | |
let side = Number(prompt("Enter square side",1)); | |
let result = side * side; | |
alert(result); | |
} | |
// Task 4 | |
function task4(){ | |
const mile= 0.621371; | |
let km = Number(prompt("Enter km",0)); | |
let result = km * mile; | |
alert(result); | |
} | |
// Task 5 | |
function getNumbers(){ | |
let num1 = document.getElementById("num1").value; | |
let num2 = document.getElementById("num2").value; | |
return {num1: num1, num2: num2} | |
} | |
function Add(){ | |
let {num1, num2} = getNumbers(); | |
let result = Number(num1) + Number(num2); | |
document.getElementById("result").innerHTML = result; | |
} | |
function Dedact(){ | |
let {num1, num2} = getNumbers(); | |
let result = Number(num1) - Number(num2); | |
document.getElementById("result").innerHTML = result; | |
} | |
function Multiply(){ | |
let {num1, num2} = getNumbers(); | |
let result = Number(num1) * Number(num2); | |
document.getElementById("result").innerHTML = result; | |
} | |
function Devide(){ | |
let {num1, num2} = getNumbers(); | |
let result = Number(num1) / Number(num2); | |
document.getElementById("result").innerHTML = result; | |
} | |
// Task 6 | |
function task6(){ | |
let num = Number(prompt("Enter number", 0)); | |
let result = num % 2 === 0 ? "even" : "odd"; | |
alert(result); | |
} | |
// Task 7 | |
function task7(){ | |
let num = Number(prompt("Enter number",123)); | |
let num1 = num % 10 * 100; | |
let num2 = num % 100 - num % 10 ; | |
let num3 = (num - num % 100) / 100; | |
alert(num1 + num2 + num3); | |
} | |
// Task 8 | |
function task8(){ | |
let cash = Number(prompt("Enter your cash amount", 1)); | |
let price = Number(prompt("Enter your cash amount", 1)); | |
let change = cash % price; | |
let toBuy = Math.round(cash / price); | |
alert("You can buy " + toBuy + " products. Change is " + change + "") | |
} | |
// Task 9 | |
function task9(){ | |
let gig = Number(prompt("Enter space in Gb",0)) | |
let meg = gig * 1024; | |
let total = Math.round(meg / 820); | |
alert(`You can fit ${total} files in drive`); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment