Directions : You are provided an html program, assignment6.html . Your responsib
ID: 3600344 • Letter: D
Question
Directions:
You are provided an html program, assignment6.html. Your responsibility is to insert the
JavaScript statements that will solve the problem discussed below, and to comment the html file with the requested information per the requirements.
For the JavaScript, you will only complete the section inside of the <script> tags that are located within the provided skeleton program:
<script id="COMPLETE_THIS_SECTION_ASSIGNMENT_6"> Insert your JavaScript code here
</script>
1
Problem to solve:
The Good Sipping Coffee Shop has a frequent buyer club that awards points to its customers based on the number of coffees purchased each month. The points are awarded as follows:
If a customer purchased no coffees, they earn 0 points
If a customer purchased 1 coffee, they earn 2 points
If a customer purchased 2 coffees, they earn 5 points
If a customer purchased 3 coffees, they earn 9 points
If a customer purchased more than 3 coffees, they earn 9 points plus an additional 2
points for each coffee above 3.
Preferred Customers receive a bonus of double award points.
The Good Sipping Coffee Shop website needs to be updated to ask the customer to enter the number of coffees purchased last month, confirm if they are a Preferred Customer, and then calculate and display the number of award points earned.
Explanation / Answer
I have two solitions for you....!
1. with Html and Javascript
2. Only using Javascript
1. Html and Javascript
<html>
<body>
<!-- Take input from user -->
Enter Number of coffees to buy:<input type=text id='numOfCoffees' value=0></input>
<!-- on submit call 'getAwardpoints' function -->
<input type=submit value=submit>
<!-- Display reward points -->
<a id=awardPoints></a>
<script id="COMPLETE_THIS_SECTION_ASSIGNMENT_6">
function getAwardpoints(){
var numCoffees = document.getElementById('numOfCoffees').value;
var isPrefferedCustomer = confirm('Press OK to continue as preffered customer CANCEL to not a preffered customer.');
var awardPoints = 0;
if (numCoffees < 1){
awardPoints = 0;
}
else if (numCoffees == 1){
awardPoints = 2;
}
else if (numCoffees == 2){
awardPoints = 5;
}
else if (numCoffees == 3){
awardPoints = 9;
}
else{
awardPoints = 9 + (numCoffees-3)*2;
}
if (isPrefferedCustomer == true){
awardPoints = awardPoints*2;
}
document.getElementById("awardPoints").innerHTML = "congrats...! You have earned " + awardPoints + " reward points.";
}
</script>
</body>
</html>
2. Only using Javascript
<html>
<body>
<script id="COMPLETE_THIS_SECTION_ASSIGNMENT_6">
// Take input from user
var numCoffees = prompt("How many coffees u want to buy", "0");
var isPrefferedCustomer = confirm('Press OK to continue as preffered customer CANCEL to not a preffered customer.');
var awardPoints = 0;
// Calculate award points
if (numCoffees < 1){
awardPoints = 0;
}
else if (numCoffees == 1){
awardPoints = 2;
}
else if (numCoffees == 2){
awardPoints = 5;
}
else if (numCoffees == 3){
awardPoints = 9;
}
else{
awardPoints = 9 + (numCoffees-3)*2;
}
if (isPrefferedCustomer == true){
awardPoints = awardPoints*2;
}
// Display award points earned
alert("congrats...! You have earned " + awardPoints + " reward points.");
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.