Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions starter-code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Pizza Builder</title>
<link rel="stylesheet" href="pizza.css">
<link rel="stylesheet" href="pizza.css" />
</head>

<body>
Expand All @@ -26,10 +26,10 @@ <h1>Pizza Builder</h1>
<button class="btn btn-green-peppers active">Green peppers</button>
</li>
<li>
<button class="btn btn-sauce active">White sauce</button>
<button class="btn btn-sauce ">White sauce</button>
</li>
<li>
<button class="btn btn-crust active">Gluten-free crust</button>
<button class="btn btn-crust ">Gluten-free crust</button>
</li>
</ul>
</div>
Expand All @@ -44,8 +44,8 @@ <h2>Your pizza's price</h2>
<li>$1 pepperonni</li>
<li>$1 mushrooms</li>
<li>$1 green peppers</li>
<li>$3 white sauce</li>
<li>$5 gluten-free crust</li>
<li style="display: none;">$3 white sauce</li>
<li style="display: none;">$5 gluten-free crust</li>
</ul>
<strong>$21</strong>
</aside>
Expand Down
48 changes: 48 additions & 0 deletions starter-code/pizza.js
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
// Write your Pizza Builder JavaScript in this file.
$(() => updatePrice());

const hideShow = element => {
$(`.${element}`).css("display") == "none"
? $(`.${element}`).show()
: $(`.${element}`).hide();
updatePrice();
};

function updatePrice() {
let base = 10;
for (let i = 1; i < 6; i++) {
if ($(`.price ul li:nth-child(${i})`).css("display") != "none") {
let price = $(`.price ul li:nth-child(${i})`).html();
base += parseInt(price[1]);
}
}
$(".price strong").html(`$${base}`);
}
$("button.btn-pepperonni").on("click", function() {
hideShow("pep");
hideShow("price ul li:nth-child(1)");
$(this).toggleClass("active");
});

$("button.btn-mushrooms").on("click", function() {
hideShow("mushroom");
hideShow("price ul li:nth-child(2)");
$(this).toggleClass("active");
});

$("button.btn-green-peppers").on("click", function() {
hideShow("green-pepper");
hideShow("price ul li:nth-child(3)");
$(this).toggleClass("active");
});

$("button.btn-sauce").on("click", function() {
$(".sauce").toggleClass("sauce-white");
hideShow("price ul li:nth-child(4)");
$(this).toggleClass("active");
});

$("button.btn-crust").on("click", function() {
$(".crust").toggleClass("crust-gluten-free");
hideShow("price ul li:nth-child(5)");
$(this).toggleClass("active");
});