javascript og lit css
This commit is contained in:
parent
fcbb649185
commit
fe0b5a944b
8 changed files with 156 additions and 103 deletions
49
intro_js/betale.html
Normal file
49
intro_js/betale.html
Normal file
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>JS intro variable opertaor og parametre</title>
|
||||
</head>
|
||||
<style>
|
||||
#app {
|
||||
display: grid;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
Per har betalt:<input type="number" id="per"><br />
|
||||
Paal har betalt:<input type="number" id="paal"><br/>
|
||||
Espen har betalt:<input type="number" id="espen"><br/>
|
||||
<button onclick="calculate()">Beregne</button>
|
||||
|
||||
<div id="app"></div>
|
||||
|
||||
<script>
|
||||
|
||||
function calculate() {
|
||||
let amountPayedPer = document.getElementById("per").valueAsNumber;
|
||||
let amountPayedPaal = document.getElementById("paal").valueAsNumber;
|
||||
let amountPayedEspen = document.getElementById("espen").valueAsNumber;
|
||||
let totalAmountPayed = amountPayedPer + amountPayedPaal + amountPayedEspen;
|
||||
let costPerPerson = totalAmountPayed / 3;
|
||||
let owesPer = costPerPerson - amountPayedPer;
|
||||
let owesPaal = costPerPerson - amountPayedPaal;
|
||||
let owesEspen = costPerPerson - amountPayedEspen;
|
||||
|
||||
document.getElementById("app").innerHTML = /*HTML*/ `
|
||||
Per har betalt: ${amountPayedPer}<br/>
|
||||
Paal har betalt: ${amountPayedPaal}<br/>
|
||||
Espen har betalt: ${amountPayedEspen}<br/>
|
||||
Sum betalt: ${totalAmountPayed}<br/>
|
||||
Kostnad per person: ${costPerPerson}<br/>
|
||||
Per skylder: ${owesPer}<br/>
|
||||
Paal skylder: ${owesPaal}<br/>
|
||||
Espen skylder: ${owesEspen}<br/>
|
||||
`;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue