Assignment: A3 Task3: Write your Own Code
Write a JavaScript program (T3.html) to compute the commission based on the sales value.
The commission is calculated as:
Sales value >=3000 -> 4% of sales value
Sales value >= 2000 -> 3% of sales value
Sales value >=1000 -> 2% of sales value
Sales value <1000 and >0 -> fixed value : $8.00
Sales value <=0 -> $0.00
The program must have the following features:
• Prompt the user to enter a sales value;
• Save the value entered into a variable.
• After the user input is recorded into a variable, the program should check few things as follow:
The program should check if the value entered is a number.
The program should check if the value entered is between 0-6000.
Finally, if value entered is outside the limits or not a number, display a message saying “Sales
Value must be between 0-6000 only. Please re-enter the value”. Note: (use alert to display the
message).
• If the value entered it is a number between 0-6000 , compute the commission and display the value in an alert
message
o Here is an output example to help you display the message:
The sales value is $5000. The commission is 4% of sales value.
The commission value is $200.
• Use Comments explaining how the program works
[SIZE=4][B][COLOR=”#0000CD”]My Code:
[CODE]<script type=”text/javascript”>
var mySales = prompt(“Enter your total sales”, 0);
//var = parseInt(mySales); //If I try to use the code with this line in, the code will not run
var percent = 0.0;
var fixed = 0.00;
if (isNaN(mySales))
{
alert(“Sales Value must be betwen 0-6000 only. Please re-enter the value.”);
}
else if (!(mySales >=0 && mySales <=6000))
{
alert(“Sales Value must be betwen 0-6000 only. Please re-enter the value.”);
}
//As per the assignment I need to check that the value entered is a number and that the value entered is between 0 and 6000.
//How do I stop the rest of the code from running after the alert and just reset to the beginning prompt of entering a value?
if (mySales <= 0)
{
percent = .00;
}
else if (mySales >0 && mySales < 1000)
{
fixed = 8.00;
}
else if (mySales >= 1000 && mySales < 2000)
{
percent = .02;
}
else if (mySales >= 2000 && mySales < 3000)
{
percent = .03;
}
else if (mySales >= 3000)
{
var percent = .04;
}
var commission = mySales * percent || fixed;
alert(” The sales value is $” + parseInt (mySales) + “.” + “n” + ” The commission is ” + (percent * 100) + “% of sales value.” + “n” + ” The commission value is $” + commission + “.00.”);
</script>
Thank you!