Notices
The Basement Non-Honda/Acura discussion. Content should be tasteful and "primetime" safe.

anyone want to help me with some basic javascript with arrays and loops? :hs:

Thread Tools
 
Old 11-08-2007, 02:10 PM
  #1  
RB26DETT
Eagles > NFL
Thread Starter
 
RB26DETT's Avatar
 
Join Date: Jul 2003
Location: nj
Posts: 10,225
Likes: 0
Received 0 Likes on 0 Posts
Default anyone want to help me with some basic javascript with arrays and loops? :hs:

its real easy, i think i got a lot of it, but i need help

AIM me: xdjshine

reward? :rick:
Old 11-08-2007, 02:11 PM
  #2  
LT
The deer had to die!
 
LT's Avatar
 
Join Date: Jun 2002
Location: Fussa, Japan
Posts: 39,835
Likes: 0
Received 0 Likes on 0 Posts
Default

Nah.
Old 11-08-2007, 02:29 PM
  #3  
v6_accord_jerz
Stupid Power Ball
 
v6_accord_jerz's Avatar
 
Join Date: Jun 2006
Location: Dirty Jersey
Posts: 11,619
Likes: 0
Received 0 Likes on 0 Posts
Default

Interested in reward.........what is it?
Old 11-08-2007, 02:41 PM
  #4  
RB26DETT
Eagles > NFL
Thread Starter
 
RB26DETT's Avatar
 
Join Date: Jul 2003
Location: nj
Posts: 10,225
Likes: 0
Received 0 Likes on 0 Posts
Default

a blowjob
Old 11-08-2007, 02:44 PM
  #5  
v6_accord_jerz
Stupid Power Ball
 
v6_accord_jerz's Avatar
 
Join Date: Jun 2006
Location: Dirty Jersey
Posts: 11,619
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by RB26DETT
a blowjob
http://www.barbie-bridgette.com/info.htm
Old 11-08-2007, 05:52 PM
  #6  
RB26DETT
Eagles > NFL
Thread Starter
 
RB26DETT's Avatar
 
Join Date: Jul 2003
Location: nj
Posts: 10,225
Likes: 0
Received 0 Likes on 0 Posts
Default

ok, i'm stuck again. for real this time. the reward part. like really for real.

Marshy, the arrays in the table didn't work at all...

Marshy helped me out with what I got so far. And I'm also stuck now. I have no clue what to do next. I've tried w3schools.com and that junk..

This is my assignment:

This assignment consists of two parts: username/password authorization and finding cost of purchase of multiple products using loops with arrays.
Start your assignment with a welcome message using an alert box :
Welcome to Bill’s Sporting Goods.

Create two arrays of length five holding the following usernames and corresponding passwords
USERNAME ARRAY: Brad, Tom, Bruce, Justin, Tommy

PASSWORD ARRAY: Jennifer, Nicole, Demi, Cameron, Pamela

Using two prompt statements ask the user to enter a username and password. If the username-password pair matches one of the five stored pairs, allow access to the rest of the code i.e. proceed to take their order details. If the username-password pair does not match any of the options, using an alert display
“Bad Username or Password entered”

If a bad username or password is entered, loop back to take new inputs. This is repeated at most three times. If on the third time too, a bad username or password is entered, display the message
“Access Denied. Try again later”

(This is a security measure in many online authorization systems. The system allows a few wrong tries, else it locks down. This helps in avoiding hacking by randomly or exhaustively guessing usernames and passwords)

If a right username and password pair is inputted, display the following message using the username inputted.
“Welcome Bruce. What products do you want to buy today?”

Now, we proceed to the second part of this assignment. You will need to declare three arrays for [Product Name], [Price] and [Discount]
This part involves using a loop. Within the loop you take the input for the product name and using an if-else structure you will find the corresponding price and discount.
Within the loop, take the input from the user for [Product Name].
Use a if-else statement to compare [Product Name] with those in the table. Based on this determine the price and discount.
Save these values in the [Product Name], [Price] and [Discount] arrays.
NOTE: Handle the case where the product name entered by the customer does not match any of the five products sold by the store. In this case, no values should be added to the three arrays and instead an error message should be given like:
“Sorry, we did not recognize your product name. Try again.”

At this point, using a confirm method ask the user if the user wants to order one more product. Your confirm message should look like
Do you want to continue? Click on Ok to input details for one more product.

If the user clicks on Ok, loop back to take the inputs for one more product. If the user clicks on Cancel, stop the loop and proceed to the output part of the program.
Lastly output the detailed bill and as summary output the total cost of the purchase. You will need to calculate the price after the discount based on the discount and the price using the formula
(price after discount) = (price before discount) * (1 – discount)

Finally, your output will have the following format:
Final Bill
Product 1:

Product Name: Skis

Price: $1000

Price after discount: $900



Product 2:

Product Name: Sleds

Price: $2000

Price after discount: $1600



Product 3:

Product Name: Ice skates

Price: $ 200

Price after discount: $180


Total cost of purchase after discounts: $ 2680
This is my code so far:

<script type="text/javascript">

alert("<i>Welcome to ******'s Sporting Goods.</i>");

var arr = new Array(5)
arr[0] = "Brad"
arr[1] = "Tom"
arr[2] = "Bruce"
arr[3] = "Justin"
arr[4] = "Tommy"

var arr2 = new Array(5)
arr2[0] = "Jennifer"
arr2[1] = "Nicole"
arr2[2] = "Demi"
arr2[3] = "Cameron"
arr2[4] = "Pamela"

var arr3 = new Array(5)
arr3[0] = "Snow boards"
arr3[1] = "Sleds"
arr3[2] = "Ice skates"
arr3[3] = "Snow tubes"
arr3[4] = "Skis"

var arr4 = new Array(5)
arr4[0] = "$750"
arr4[1] = "$2000"
arr4[2] = "$200"
arr4[3] = "$500"
arr4[4] = "$1000"

var arr5 = new Array(5)
arr5[0] = ""
arr5[1] = "20%"
arr5[2] = ""
arr5[3] = "10%"
arr5[4] = ""

var i=o

var username;

var password;

var j=true;

var product;


var logins = 0;
do{
if (i<5){
if (arr[i] == username && arr2[i] == password){
product = prompt("Welcome "+username+". What products do you want
to buy today?");
break;
}
}
else {
alert("Bad username or password entered");
i++;

}
}
while(logins < 3);
if (logins >= 3){
alert("Access denied! Too many failed login attempts!");
}

if (username== arr[i] && password== arr2[i])

{
product = prompt("Welcome "+username+". What products do you want to buy today?");
while (j == true)
{
product = prompt("What would you like to order?","");


aaaand i'm stuck there.
First, did I get the array thing right? Specifically the username/password part.
Second, what the hell do I do next
I don't know how to use the arrays to look up the price and discount..

Last edited by RB26DETT; 11-08-2007 at 05:55 PM.
Old 11-08-2007, 05:54 PM
  #7  
Just Janna
Cake or Death?
 
Just Janna's Avatar
 
Join Date: Jun 2003
Location: NJ
Posts: 20,749
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by RB26DETT
a blowjob
I lol'd for reals.
Old 11-08-2007, 05:54 PM
  #8  
Civic2Scooby
 
Civic2Scooby's Avatar
 
Join Date: Jul 2003
Location: michigan
Posts: 28,282
Likes: 0
Received 0 Likes on 0 Posts
Default

just use IF WHEN h:




All times are GMT -8. The time now is 11:46 PM.