var salaryCalculator = function (baseSalary) { this.baseSalary = baseSalary; this.calculateSalary = function (profession) { if (profession === "mechanic") { var multiplier = 1.8; } else if (profession === "developer") { var multiplier = 2.8; } else if (profession === "doctor") { var multiplier = 3.2; } else if (profession === "professor") { var multiplier = 4.1; } else { return this.baseSalary * multiplier; } } } var salaryCalculator1 = new salaryCalculator(800); var salary = salaryCalculator.calculateSalary("mechanic"); var salary = salaryCalculator.calculateSalary("developer"); var salary = salaryCalculator.calculateSalary("doctor"); var salary = salaryCalculator.calculateSalary("professor"); console.log(salaryCalculator1.calculateSalary()); 
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <title>Septinta pamoka</title> </head> <body> <script type="text/javascript" src="main.js"></script> </body> </html> 

 введите сюда код 

Closed due to the fact that off-topic participants are Vladimir Martyanov , Ivan Pshenitsyn , user194374, aleksandr barakin , Kromster August 20 '16 at 16:33 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Vladimir Martyanov, Ivan Pshenitsyn, Community Spirit, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What kind of error and where does it occur? - Vladimir Martyanov

2 answers 2

I'm sure your code is not doing anything right now, since you only declare variables. But the error is clear:

 var salaryCalculator1 = new salaryCalculator(800); 

Here you declared the variable salaryCalculator1 , but then you use the name of the function that does not have static methods:

 var salary = salaryCalculator.calculateSalary("mechanic"); 

Which gives an error. correct code:

 var salaryCalculator = function (baseSalary) { this.baseSalary = baseSalary; this.calculateSalary = function (profession) { if (profession === "mechanic") { var multiplier = 1.8; } else if (profession === "developer") { var multiplier = 2.8; } else if (profession === "doctor") { var multiplier = 3.2; } else if (profession === "professor") { var multiplier = 4.1; } else { return this.baseSalary * multiplier; } } } var salaryCalculator1 = new salaryCalculator(800); var salary = salaryCalculator1.calculateSalary("mechanic"); var salary = salaryCalculator1.calculateSalary("developer"); var salary = salaryCalculator1.calculateSalary("doctor"); var salary = salaryCalculator1.calculateSalary("professor"); console.log(salaryCalculator1.calculateSalary()); 

    salaryCalculator is a class constructor, an error causes an attempt to use a class method (and not a class object method).

    Besides,

    return this.baseSalary * multiplier; for the right wages will not be caused due to being in else

    console.log(salaryCalculator1.calculateSalary()); does not contain a required parameter in the function call

    and the same variable is declared 4 times ..

     var salaryCalculator = function (baseSalary) { this.baseSalary = baseSalary; this.calculateSalary = function (profession) { var multiplier; if (profession === "mechanic") { multiplier = 1.8; } else if (profession === "developer") { multiplier = 2.8; } else if (profession === "doctor") { multiplier = 3.2; } else if (profession === "professor") { multiplier = 4.1; } else { throw new Error("Такой профессии нет"); } return this.baseSalary * multiplier; } } var salaryCalculator1 = new salaryCalculator(800); var salary1 = salaryCalculator1.calculateSalary("mechanic"); var salary2 = salaryCalculator1.calculateSalary("developer"); var salary3 = salaryCalculator1.calculateSalary("doctor"); var salary4 = salaryCalculator1.calculateSalary("professor"); console.log([salary1,salary2,salary3,salary4]); 
     <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <title>Septinta pamoka</title> </head> <body> <script type="text/javascript" src="main.js"></script> </body> </html>