This repository has been archived by the owner on Dec 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Committing items from Pearl's final todo list.
- Loading branch information
Pearl Chen
committed
Oct 8, 2012
1 parent
135dce5
commit f4ad6c6
Showing
13 changed files
with
230 additions
and
24 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script> | ||
function validateForm() { | ||
|
||
// automagically get the typed values from the form | ||
var name = document.getElementById("name").value; | ||
var address = document.getElementById("address").value; | ||
var city = document.getElementById("city").value; | ||
var postal = document.getElementById("postal").value; | ||
|
||
/* *** YOUR CODE _BELOW_ HERE **** */ | ||
|
||
/* 1. Declare 4 variables named | ||
"nameIsBlank", "addressIsBlank", "cityIsBlank", and "postalIsBlank" | ||
that will each hold Boolean values. */ | ||
|
||
|
||
/* 2a. Use conditional if/else statements on the variables | ||
"name", "address", "city", and "postal" to determine | ||
if each individual field is not blank. | ||
|
||
Update their respective Boolean variables (e.g. "nameIsBlank") | ||
based on their individual if/else statements. */ | ||
|
||
|
||
/* 3. In a final conditional, test ALL FOUR Boolean variables | ||
and alert the proper message. Below are some alerts you can use. */ | ||
|
||
alert( "Sorry there are errors. Form fields cannot be blank!" ); | ||
alert( "Thank you for your order!" ); | ||
|
||
/* *** YOUR CODE ^ABOVE^ HERE **** */ | ||
} | ||
</script> | ||
|
||
Name: | ||
<input type="text" id="name" /> | ||
<br /> | ||
Address: | ||
<input type="text" id="address" /> | ||
<br /> | ||
City: | ||
<input type="text" id="city" /> | ||
<br /> | ||
Postal Code: | ||
<input type="text" id="postal" /> | ||
<br /> | ||
<br /> | ||
<button onclick="validateForm()">Check out now!</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
function validateForm() { | ||
|
||
// automagically get the typed values from the form | ||
var address = document.getElementById("address").value; | ||
|
||
/* 1. Use a conditional if/else statement on the "address" variable | ||
to determine if the address field is (or is not) blank, | ||
then show the proper error or confirmation alert message. */ | ||
|
||
/* *** YOUR CODE _BELOW_ HERE **** */ | ||
|
||
alert( "Sorry there are errors. Form fields cannot be blank!" ); | ||
alert( "Thank you for your order!" ); | ||
|
||
/* *** YOUR CODE ^ABOVE^ HERE **** */ | ||
} | ||
</script> | ||
|
||
Address: | ||
<input type="text" id="address" /> | ||
<br /> | ||
<br /> | ||
<button onclick="validateForm()">Check out now!</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script> | ||
|
||
var quantity = 0; | ||
|
||
function addItem(){ | ||
quantity = quantity + 1; | ||
refreshTotal(); | ||
} | ||
|
||
function removeItem(){ | ||
/* 1. Use a conditional if or if/else statement on the "quantity" variable | ||
to avoid having negative products. */ | ||
/* *** YOUR CODE _BELOW_ HERE **** */ | ||
|
||
quantity = quantity - 1; | ||
|
||
/* *** YOUR CODE ^ABOVE^ HERE **** */ | ||
refreshTotal(); | ||
} | ||
|
||
function checkout() { | ||
/* 2. Use a conditional if/else statement on the "quantity" variable | ||
to determine if the shopping cart is (or is not) empty, then | ||
show the correct popup message. */ | ||
/* *** YOUR CODE _BELOW_ HERE **** */ | ||
|
||
alert( "Sorry, you don't have anything in your cart!" ); | ||
alert( "Thank you for your order!" ); | ||
|
||
/* *** YOUR CODE ^ABOVE^ HERE **** */ | ||
} | ||
|
||
function refreshTotal() { | ||
|
||
// calculate the totalCost with a fixed price of $20. | ||
var totalCost = quantity * 20; | ||
|
||
// then update the quantity text field | ||
document.getElementById('updateQuantity').value = quantity; | ||
|
||
// update the total cost text field | ||
// 3. A nice to have: Put a dollar sign in front of the total cost | ||
/* *** YOUR CODE _BELOW_ HERE **** */ | ||
|
||
document.getElementById('updateTotal').value = totalCost; | ||
|
||
/* *** YOUR CODE ^ABOVE^ HERE **** */ | ||
} | ||
</script> | ||
|
||
<div id="exercise2" style="text-align: center;"> | ||
<img src="http://pchen.github.com/LLC-JavaScript/exercises/assets/plush-android.jpg" width="195" height="195" /> | ||
<br /> | ||
<button onclick="addItem();">Add</button> | ||
<button onclick="removeItem();">Remove</button> | ||
<br /> | ||
Quantity | ||
<input type="text" id="updateQuantity" value="0" readonly style="text-align:center; width: 20px; border: 1px solid #ccc;"/> | ||
<br /> | ||
<br /> | ||
Total Cost: | ||
<input type="text" id="updateTotal" value="" readonly style="border: 1px solid #ccc;"/> | ||
<br /> | ||
<br /> | ||
<button onclick="checkout();">Check out now!</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters