2 changed files with 61 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|||
<title>JS+HTML základy</title> |
|||
</head> |
|||
<body> |
|||
<h1>JS+HTML základy</h1> |
|||
<input type="number" name="num1" id="num1" placeholder="Číslo 1"> |
|||
<input type="number" name="num2" id="num2" placeholder="Číslo 2"> |
|||
<br> |
|||
<div style="margin: 10px;"> |
|||
<button onclick="vypocitat('+')">SEČÍST</button> |
|||
<button onclick='vypocitat("-")'>ODEČÍTAT</button> |
|||
<button onclick='vypocitat("*")'>NÁSOBIT</button> |
|||
<button onclick='vypocitat("/")'>DĚLIT</button> |
|||
</div> |
|||
<br> |
|||
<p>Výsledek: <span id="vysledek"></span></p> |
|||
|
|||
<script src="js/app.js"></script> |
|||
</body> |
|||
</html> |
@ -0,0 +1,37 @@ |
|||
console.log("app.js spuštěn") |
|||
|
|||
let x,y,vysledek; |
|||
|
|||
function vypocitat(symbol){ //AltGr + b|n = {|}
|
|||
x = Number(document.getElementById("num1").value) |
|||
y = parseInt(document.getElementById("num2").value) |
|||
|
|||
if (symbol == "+") { |
|||
vysledek = x+y |
|||
} else if (symbol == "-") { |
|||
vysledek = x-y |
|||
} else if (symbol == "*") { |
|||
vysledek = x*y |
|||
} else if (symbol == "/") { |
|||
if (y == "0") { |
|||
vysledek = "Nelze dělit nulou" |
|||
} else { |
|||
vysledek = x/y |
|||
} |
|||
} else { |
|||
vysledek = "chyba" |
|||
} |
|||
|
|||
console.log(x + symbol + y + "=" + vysledek) |
|||
document.getElementById("vysledek").innerText = vysledek |
|||
} |
|||
|
|||
function spocitejVse() { |
|||
x = Number(document.getElementById("num1").value) |
|||
y = parseInt(document.getElementById("num2").value) |
|||
|
|||
console.log(x + "+" + y + "=" + (x+y)) |
|||
console.log(x + "-" + y + "=" + (x-y)) |
|||
console.log(x + "*" + y + "=" + (x*y)) |
|||
console.log(x + "/" + y + "=" + (x/y)) |
|||
} |
Loading…
Reference in new issue