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
14 changes: 7 additions & 7 deletions starter-code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ <h1>Pizza Builder</h1>
<h2>Your pizza's price</h2>

<b>$10 cheese pizza</b>
<ul>
<li>$1 pepperonni</li>
<li>$1 mushrooms</li>
<li>$1 green peppers</li>
<li>$3 white sauce</li>
<li>$5 gluten-free crust</li>
<ul class="ul">
<li id="li-1">$1 pepperonni</li>
<li id="li-2">$1 mushrooms</li>
<li id="li-3">$1 green peppers</li>
<li id="li-4">$3 white sauce</li>
<li id="li-5">$5 gluten-free crust</li>
</ul>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think naming these li-1 is a wee bit redundant, you are able to select them using the right query methods (e.g. eq(i) which gets the element at index i. If anything, I would give them a class that corresponds to the ingredient or to the ingredient button, if you find that useful in your implementation.

<strong>$21</strong>
<strong>$<span class="total">21</span></strong>
</aside>
<!-- End Price -->

Expand Down
15 changes: 12 additions & 3 deletions starter-code/pizza.css
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ p.description {
}

/*--- Crust & Sauce ---*/


.crust {
width: 700px;
height: 700px;
Expand All @@ -331,9 +333,9 @@ p.description {
}

.crust-gluten-free {
background-color: #e0d5cf;
box-shadow: inset 0 0 40px #d3c3bb;
}
background-color: #e0d5cf;
box-shadow: inset 0 0 40px #d3c3bb;
}

.sauce {
position: absolute;
Expand Down Expand Up @@ -1036,4 +1038,11 @@ footer a:hover {
footer {
margin: 70px 0 10px 0;
}



}

.hidden {
display: none;
}
130 changes: 130 additions & 0 deletions starter-code/pizza.js
Original file line number Diff line number Diff line change
@@ -1 +1,131 @@
// Write your Pizza Builder JavaScript in this file.
$("document").ready(function () {

// make crust and red sauce default on load
$(".crust").removeClass("crust-gluten-free");

$(".sauce").removeClass("sauce-white");

//setting default price on load
$(".total").html("13");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better (more explicit) to have a function called setupDefaultView() or something that shows what you are doing.




// "if the ingredient is turned on, its button should have active."
//removing active class so it will appear again on click.

// $(".btn-green-peppers").removeClass("active");

// $(".btn-mushrooms").removeClass("active");

// $(".btn-pepperonni").removeClass("active");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure you do a "clean up" commit before you submit a pull request. Get rid of all unnecessary comments, extra empty lines (you should typically be using 1 at most) and any other unused variables or functions

$(".btn-sauce").removeClass("active");

$(".btn-crust").removeClass("active");

//remove white sauce and gluten free from price list on load
$("#li-5").addClass("hidden") //crust
$("#li-4").addClass("hidden") //sauce



//adding/removing ingredientes by adding the class hidden
//adding/removing class active
$(".btn-green-peppers").click(function () {
$(".green-pepper").toggleClass("hidden");
$(".btn-green-peppers").toggleClass("active");
$("#li-3").toggleClass("hidden");
var className = $(this).attr('class')

var total = $(".total").html();

if (className === "btn btn-green-peppers active") {
$(".total").html(parseFloat(total) + 1);

} else {
$(".total").html(parseFloat(total) - 1);
}

});


$(".btn-mushrooms").click(function () {
$(".mushroom").toggleClass("hidden");
$(".btn-mushrooms").toggleClass("active");
$("#li-2").toggleClass("hidden");
var className = $(this).attr('class')

var total = $(".total").html();

if (className === "btn btn-mushrooms active") {
$(".total").html(parseFloat(total) + 1);

} else {
$(".total").html(parseFloat(total) - 1);
}

});

$(".btn-pepperonni").click(function () {
$(".pep").toggleClass("hidden");
$(".btn-pepperonni").toggleClass("active");
$("#li-1").toggleClass("hidden");

var className = $(this).attr('class')

var total = $(".total").html();

if (className === "btn btn-pepperonni active") {
$(".total").html(parseFloat(total) + 1);

} else {
$(".total").html(parseFloat(total) - 1);
}
});

$(".btn-sauce").click(function () {
$(".sauce").toggleClass("sauce-white");
$(".btn-sauce").toggleClass("active");
$("#li-4").toggleClass("hidden");
//var className stores all class values of sauce
var className = $(this).attr('class')

//var total contains the initial total price before click
var total = $(".total").html();

if (className === "btn btn-sauce active") {
$(".total").html(parseFloat(total) + 3);

} else {
$(".total").html(parseFloat(total) - 3);
}

});

$(".btn-crust").click(function () {
$(".crust").toggleClass("crust-gluten-free");
$(".btn-crust").toggleClass("active");
$("#li-5").toggleClass("hidden");

//var className contains the complete class value
var className = $(this).attr('class')

//var total contains the initial total price before click
var total = $(".total").html();

//In case the button has active in his class (which means pressed), i need to add +5 to the price
if (className === "btn btn-crust active") {
$(".total").html(parseFloat(total) + 5);
//In case the button crust does not have active in the class (which means unpressed) i need to extract -5 from the price.
} else {
$(".total").html(parseFloat(total) - 5);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it might be an idea to declare the variables total and className globally, reassign them on click then write a function that takes in these two variables and updates $(".total"). This way you can avoid duplicate code 😉


});

});