-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJs Object Project1.html
51 lines (48 loc) · 1.41 KB
/
Js Object Project1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Js Object Project1</title>
</head>
<body>
<script>
const menu = {
_meal: "",
_price: 0,
set meal(mealToCheck) {
if (typeof mealToCheck === "string") {
return (this._meal = mealToCheck);
console.log((this._meal = mealToCheck));
}
},
set price(priceToCheck) {
if (typeof priceToCheck === "number") {
return (this._price = priceToCheck);
console.log((this._price = priceToCheck));
}
},
get todaysSpecial() {
if (this._meal && this._price) {
return `Today's special is ${this._meal} for $${this._price}!`;
console.log(this._meal);
console.log(this._price);
} else {
return "Meal or price was not set Currently";
}
},
};
const mealOption = ["apple", "banana", "Kiwi", "Burger"];
menu.meal = mealOption[Math.floor(Math.random() * mealOption.length)];
let mealPrice = () => {
if (menu.meal === "pizza") {
return (mealPrice = 3.5);
} else {
return (mealPrice = 2.5);
}
};
menu.price = mealPrice();
console.log(menu.todaysSpecial);
</script>
</body>
</html>