Learning Objectives: This assignment is designed to practice: 1. Basic understan
ID: 3602192 • Letter: L
Question
Learning Objectives: This assignment is designed to practice: 1. Basic understanding of JavaScript variables, including; aThe declaration, initialization and assignment processes 2.Obtain user input by via the prompt() function and present output to the user through the alert() function 3.Data type conversion in variables (strings to numbers, convert to upper case) 4.Use of the conditional if and if/else statements 5.Use of arithmetic and logic operators 6.Use of comments 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 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. Requirements: For this assignment; 1.Your program will calculate the award points as described above. 2.You will generate HTML comments to add your name, section and TA name. Each on a separate line within the tags. This will (should) NOT be visible in the document on the web browser. 3.You will then add JavaScript code to the provided assignment6.html skeleton file within the 4.A typical program flow would declare the variables needed to solve the problem, initialize the variables, solicit input, perform the data manipulation and/or calculations and display the result. 5.Utilize JavaScript comments to explain the steps you are preforming within your code. A JavaScript comment’s form is: /* Place your comment between the stars */ 6.You will utilize prompt() functions to request input from the customer. Your message should be descriptive enough to solicit data from someone not familiar with the assignment. 2 7.You will utilize the alert() function to display your output as a clear and understandable message to the customer. 8.Variable names should be descriptive. For example, if a program is calculating the total dollar amount paid for a bill at a restaurant, it may have a variable named tipAmount. 9.Utilize at least one if/else statement. Consider using the if/else in determining the bonus points. Additional Information: Since the contents of a text box, which is what the prompt() function generates, is going to be used in mathematical operations, use the function parseInt() to convert the text to a number. Otherwise your calculation operations will not perform as expected. Example: variableName = parseInt(variableName) To simplify the comparison of solicited text, it is often easier to convert this text to upper case. Example: variableName = variableName.toUpperCase();
Explanation / Answer
1. Basic understanding of JavaScript variables, including; aThe declaration, initialization and assignment processes
javascript variables are defined using var keyword like
var x; /* known as declaration */
var x = 10; /* declaring and defining x as number and assigning 10 to x */
x = 15 /* assignment */
var x = 25 /* already x is created in the first step, but javascript wont throw an error like c or c++ */
y = 20; /* Javascript will automatically creates a variable if not declared before*/
Obtain user input by via the prompt() function and present output to the user through the alert() function
user_input = prompt("enter your input"); /* this will give you a dialog box with input field and the input is stored in the variable user_input
alert(user_input); /* alert is used to display the message passed inside alert function */
3.Data type conversion in variables (strings to numbers, convert to upper case)
var x = "123"; /* x is a string */
var y = parseInt(x); /* parseInt is used to convert strings to integers */
var a = "1.012";
var b = parseFloat(a); /* parseFloat is used to convert strings to float values */
var x = "a"; /* x is in lowecase */
y = x.toUpperCase() /* used to convert to uppercase */
b = y.toLowerCase() /* used to convert to lowercase */
Use of the conditional if and if/else statements
x = 10
if(x<10){
alert("x is less than 10");
}else if(x ==10){
alert("x is equal to 10");
}else{
alert("x is greater than 10");
}
a conditional operator is used to check single or multiple conditions, its similar to the conditional operators in c/c++/java
Use of arithmetic and logic operators
The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).
Remainder (%)
Increment (++)
Decrement (--)
Unary negation (-)
Unary plus (+)
Exponentiation operator (**) are the arthimetic operators in javascript
Logical AND(&&)
Logical OR (||)
Logical OR (||) these are the logical operators in javascript
The Good Sipping Coffee Shop
value_str = prompt("enter no.of coffees you had last month");
prefferred_customer = confirm("Are you a prefferred customer");
value = parseInt(value_str);
if(value<0){
alert("you have entered invalid number");
}else{
award_points = 0;
if(value>=3){
award_points = 9;
value = value -3;
award_points += value*2;
}else if(value==2){
award_points = 5;
}else{
award_points = 2;
}
if(prefferred_customer){
award_points = award_points * 2;
}
alert("Your Award points are: "+ award_points);
Note: Add the HTML tags and use this code for javascript
Little Advanced Concept in Assignment:
below is the example of Destructive Assignment which is used for complex assignments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.