Question

In: Computer Science

Based on the descriptions given below, write the JavaScript codes to calculate the amount to be...

Based on the descriptions given below, write the JavaScript codes to calculate the amount to

be paid for books purchased.

 Declare all the variables used in this program.

 Ask the user to key-in the book code using a prompt() method. Store the value in a

variable named book_code.

 Ask the user to key-in the number of books purchased using a prompt() method.

Store the value in a variable named book_qty.

 Ask the user whether they have a membership card of the bookstore using a

confirm() method. Store their response in a variable named member.

 Now, using if else statement identify the book title and book price. Use the table

below as your reference.

Book Code

Book Title

Book Price (RM)

B001 or b001 E-Commerce 2019

112.00

B002 or b002 Learning Web Design

248.35

B003 or b003 Business Law

71.90

Other values

Invalid Book Code

0.00

 Based on the user’s response on bookstore membership, use if else statement to

identify:

o If the user is a member, there will be a member discount of 20%. The

membership status will be “Yes”.

o If the user is not a member, there will not be any member discount given.

The membership status will be “No”.

 Write the formula to calculate the total payment for the books purchased.

 If total payment for the books purchased is more than RM500:

o The user is eligible to get additional discount of 30%.

o Use the alert() method to display amount of total purchase and inform users

about the discount eligibility.

o Otherwise, the user is not eligible to get the 30% discount. Use the alert()

method to display amount of total purchase and inform users about the

discount ineligibility.

 Write the formula to calculate the total discount.

 Write the formula to calculate the discount amount based on the total purchase

amount.

 Write the formula to calculate the payment after deduction of discount.

 Display the output as shown in the sample output sequence.

Solutions

Expert Solution

Here is your code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>BookStore</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
</head>
<body>
<p id="demo"></p>

<header>

</header>

<script type="text/javascript">
 
var book_code = prompt("Please enter book code");

if(book_code=="B001"|| book_code=="b001"|| book_code=="B002"|| book_code=="b002"|| book_code=="B003"|| book_code=="b003"){
var book_qty = prompt("Please enter number of books purchased");
var member;
var r = confirm("Do you have a membership card of the bookstore?");
  if (r == true) {
    member = "Yes";
  } else {
    member = "No";
  }

if (book_code=="B001"|| book_code=="b001") {
var book_title="E-Commerce 2019";
var book_price=112
var tbook_price=book_price*book_qty;
var total=memberdiscount(tbook_price);
if(total>500){
  alert("You are eligible to get additional discount of 30% and the amount purchased is "+ total);
  var adddis=total-total*(30/100);
}
else{
  alert("You are not eligible to get additional discount of 30% and the amount purchased is "+ total);
  var adddis=total;
}
// alert("Book Code="+book_code+"Book Title="+book_title+" Book Price (RM)="+book_price+" Total Qty="+book_qty+" Membership Status="+member+" Total amt="+adddis); You can also get out in alert format
}
if (book_code=="B002"|| book_code=="b002") {
var book_title="Learning Web Design";
var book_price=248.35
var tbook_price=book_price*book_qty;
var total=memberdiscount(tbook_price);
if(total>500){
  alert("You are eligible to get additional discount of 30% and the amount purchased is "+ total);
  var adddis=total-total*(30/100);
}
else{
  alert("You are not eligible to get additional discount of 30% and the amount purchased is "+ total);
  var adddis=total;
}
}
if (book_code=="B003"|| book_code=="b003") {
var book_title="Business Law";
var book_price=71.90
var tbook_price=book_price*book_qty;
var total=memberdiscount(tbook_price);
if(total>500){
  alert("You are eligible to get additional discount of 30% and the amount purchased is "+ total);
  var adddis=total-total*(30/100);
}
else{
  alert("You are not eligible to get additional discount of 30% and the amount purchased is "+ total);
  var adddis=total;
}
}
}
else{
  alert("Invaild Book Code");
  abort();
}
function memberdiscount(book_price) {
if(member=="Yes")
{
  var booktotal=book_price*(20/100);
  return book_price-booktotal;
}
else{
  var booktotal=0;
 return book_price-booktotal; 
}
}
 document.getElementById("demo").innerHTML ="<b>Purchased Details:</b><br>"+ "Book Code="+book_code+"<br>Book Title="+book_title+"<br>Book Price (RM)="+book_price+"<br>Total Qty="+book_qty+"<br>Membership Status="+member+"<br>Total amt to pay:="+adddis;

</script>


</body>
</html>

----------------------------------------

OUTPUT:

----------------------------------

Please rate and feel free to ask if you need any modifications. :)


Related Solutions

Javascript Calculator Algorithm to calculate a tip percentage given the bill amount and total bill including...
Javascript Calculator Algorithm to calculate a tip percentage given the bill amount and total bill including tip. Asker suer for bill without tip: Ask the user for total bill with tip: Ask the user how many people splitting bill: Submit button to calculate the tip percentage
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
Match the descriptions below with the correct answer, using the letter codes shown in the table...
Match the descriptions below with the correct answer, using the letter codes shown in the table below. (8 points) A.    Realizable value B.    Percentage of receivables method C.      1/10, n/60 D.    Bad debt Expense E.      Aging of receivables F.       Direct write-off method G.     Operating cycle H.     Specific identification method I.        FOB shipping point J.        Time period assumption K.    n/10 EOM L.    Percentage of sales method M.   Permanent accounts N.    2/10, EOM O.    2/10, n/30 P.     FOB destination The economic life...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to print the type of the following variables. Please write down the codes and the output as well. x = 3.5 y = '3.5' z = {1:'John', 2:'Wick', 3:'Barry', 4:'Allen'}
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two...
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two exam scores, exam_1 and exam_2, write a program to determine if the student makes progress (exam_2 is greater than exam_1). Return “Yes” or “No”. You can use any exam_1 score and exam_2 score for this exercise.
How do you write JavaScript codes to randomly select five elements by using a single for-loop?...
How do you write JavaScript codes to randomly select five elements by using a single for-loop? How do you display the results to a html page? var password = [“x”, “y”, “z”, “1”, “2”, “3”, “test”]; Sample output: zx21y
Based on the information given below, calculate (a) the portfolio’s return in the last 12 months...
Based on the information given below, calculate (a) the portfolio’s return in the last 12 months in the USD, (b) its return in the AUD, and (c) the standard deviation of the portfolio return. Provide all the workings (use up to 3 decimal places). Your stock portfolio consists of two American companies; Alphabet and GM. You are living in Australia and those shares are purchased in the USD. During the last 12 months, Alphabet’s stock went up by 20%, while...
Based on the information given below, calculate (a) the portfolio’s return in the last 12 months...
Based on the information given below, calculate (a) the portfolio’s return in the last 12 months in the USD, (b) its return in the AUD, and (c) the standard deviation of the portfolio return. Provide all the workings (use up to 3 decimal places). Your stock portfolio consists of two American companies; Alphabet and GM. You are living in Australia and those shares are purchased in the USD. During the last 12 months, Alphabet’s stock went up by 20%, while...
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using...
Write a JavaScript function to calculate the surface area of a sphere. Input the radius using a NumericUpDown. Have the function calculate the surface area and display it on your page. Label the inputs and the output on your page. Change the title to "Oh, Boy! JavaScript!". Put your name at the top in camelCase. Put your major at the bottom in camelCase.
Put your name on the first line in camelCase. Write a JavaScript function to calculate the...
Put your name on the first line in camelCase. Write a JavaScript function to calculate the revenue for blocks sales. Input the number of wooden blocks, the number of plastic blocks and the number of rubber blocks. Wooden blocks are $5. Plastic blocks are $2 and rubber blocks are $4. Calculate the cost for each type of block. Calculate the total cost. Display the four outputs on the page. Label the inputs and the output on your page. Change the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT