Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Javascript assignment for college due 4/28. Please help - losing my mind.


  • Please log in to reply
1 reply to this topic

#1 Cecilia421

Cecilia421

  • Members
  • 114 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:Walton, KY
  • Local time:12:11 AM

Posted 26 April 2015 - 02:44 PM

Hi, everybody,

 

I have this assignment for a college course. My professor is not replying to my emails. I've had no experience with programming at all, and up until now, the course was entirely HTML/CSS. I'm supposed to write a Javascript program that will use prompt methods to take user information, process a microchip order and calculate the total cost with discount. Here is the code I've written. It's not working and I don't know why. Any suggestions?

 

function chipOrder(){
var answer = confirm("Order microchips?");
  if (answer) {
  var userName = prompt("Please enter your name.");
  var userAddress = prompt("Please enter your address.");
  var userPhone = prompt("Please enter your phone number.");
  var userEmail = prompt("Please enter your email.");
  var chipAmount = prompt("Please enter the number of chips you wish to order.");
  var origPrice = (chipAmount * 110);
  var discountAmount;
  if (chipAmount <= 19) {(discountAmount="0%");}
else if (20 <= chipAmount <= 49) {(discountAmount="2%");}
else if (50 <= chipAmount <= 79) {(discountAmount="4%");}
else if (80 <= chipAmount <= 99) {(discountAmount="6%");}
else (chipAmount >= 100) {(discountAmount="8%");}
  var discountPrice;
    if (chipAmount <= 19) {(discountPrice=origPrice*0);}
else if (20 <= chipAmount <= 49) {discountPrice=(origPrice * 0.02);}
else if (50 <= chipAmount <= 79) {discountPrice=(origPrice * 0.04);}
else if (80 <= chipAmount <= 99) {discountPrice=(origPrice * 0.06);}
else (chipAmount>=100) {discountPrice=(origPrice * 0.08);}
 var totalPrice=(origPrice-discountPrice);
  document.write("<h2>Customer Info</h2>");
  document.write("Name: " + userName +"<br>");
  document.write("Address: " + userAddress + "<br>");
  document.write("Phone: " + userPhone + "<br>");
  document.write("Email: " + userEmail + "<br>");
  document.write("<h2>Order Info</h2>");
  document.write("Number of chips: " + chipAmount + "<br>");
  document.write("Cost per chip: $110 <br>");
  document.write("Discount/Amount: " + discountAmount + "/$" + discountPrice + "<br>");
  document.write("$" + totalPrice + "<br>");
}
else {
document.write("Thank you for visiting. Please come again!")
}
}

"Life can only be understood backwards, but it must be lived forwards."
- Soren Kierkegaard

BC AdBot (Login to Remove)

 


#2 Cecilia421

Cecilia421
  • Topic Starter

  • Members
  • 114 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:Walton, KY
  • Local time:12:11 AM

Posted 26 April 2015 - 02:52 PM

Nevermind. I finally found a javascript checker that showed me what I was missing.

 

Ahhhhhhh!!!

 

Thanks. I feel better now.

 

Ciao!


"Life can only be understood backwards, but it must be lived forwards."
- Soren Kierkegaard




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users