-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample7getvalue.html
More file actions
62 lines (50 loc) · 1.71 KB
/
Example7getvalue.html
File metadata and controls
62 lines (50 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<label for="banana"> Banana :</label>
<input type="number" id="banana" style="width: 300px;">
<br>
<label for="apple"> Apple :</label>
<input type="number" id="apple" style="width: 300px;">
<br>
<label for="mango"> Mango :</label>
<input type="number" id="mango" style="width: 300px;">
<br>
<button onclick="calculatePrice()">Calculate Price </button>
<script>
function f7(basket, prices) {
let totalCost = 0;
for (let product in basket) {
if (prices[product]!==undefined) {
totalCost += basket[product] * prices[product];
}
}
return totalCost;
}
function calculatePrice()
{
const banana =document.getElementById("banana").value;
const apple = document.getElementById("apple").value;
const mango = document.getElementById("mango").value;
const basket = {
"Banana":banana,
"Apple":apple,
"Mango":mango
}
const price = {
"Banana":2.50,
"Apple":3.75,
"Mango":4.12
}
const result = f7(basket,price);
document.getElementById("output").innerHTML = result;
// alert("The sum of basket is :" + result);
}
</script>
<p>The sum of basket is:<p id="output"></p></p>
</body>
</html>