JavaScript function if the salary is less than 20000 it is not enough, else if t
ID: 3824402 • Letter: J
Question
JavaScript function
if the salary is less than 20000 it is not enough, else if the salary is between 20000 and 25000 it is almost enough, and (else) if the salary is greater than 25000 the salary is enough
Create the if...else if....else statement. You will need to use various operators found here: http://www.w3schools.com/js/js_comparisons.asp
1. The first test should test if the variable used to store the calculated salary (from the previous assignment) is less than 20000, If this condition is true, it should assign the value ". The salary is too little." to the undefined variable
2. The second test should test if the variable used to store the calculated salary is greater than 20000 and less than 25000 and should assign the value ". The salary is almost enough. Let’s negotiate." to the undefined variable.
3. The last test should take place by default (else), if neither of the two previous conditions are met. It will assign the value ". This is a great salary for me." to the undefined variable.
Explanation / Answer
Here goes the required javascript function for the given problem statement.
The salaryCheck function takes the salary parameter and stores the answer in the 'message' variable.
Code:
var salary;
var message="";
function salaryCheck(salary){
if(salary<=20000)
message="The salary is too little.";
else if(salary>20000&&salary<=25000)
message="The salary is almost enough. Let’s negotiate.";
else
message="This is a great salary for me.";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.