Question

In: Computer Science

Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell...

Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell that says payment is undefined. I am trying to create a main.js file that imports the function from the hr.js file; call the function passing the necessary arguments and log the result to the console.

main.js

var Dev = require("./hr.js")

const { add } = require("./hr.js")

var dev_type = 1;

var hr = 40;

console.log("your weekly payment is " + payment(dev_type, hr))

dev_type = 2;

hr = 45;

console.log("your weekly payment is " + payment(dev_type, hr));

hr.js

function payment(dev_type, hr) {

    var total_payment;

    var extra_hr;

    if (dev_type == 1) {

        if (hr <= 40) {

            total_payment = hr * 55;

        } else {

            extra_hr = hr - 40;

            total_payment = 40 * 55 + (extra_hr * 110);

        }

    }

    if (dev_type == 2) {

        if (hr <= 40) {

            total_payment = hr * 60;

        } else {

            extra_hr = hr - 40;

            total_payment = 40 * 60 + (extra_hr * 120);

        }

    }

    return total_payment;

    

}

module.exports = {add: payment}

Solutions

Expert Solution

IN YOUR CODE, YOU HAVE IMPORTED AND EXPORTED "PAYMENT" FUNCTION AS "ADD" BUT WHEN YOU CALL THAT FUNCTION YOU HAVE USED THE PAYMENT KEYWORD WHICH IS NOT DECLARED IN MAIN.JS (REFERENCE ERROR:)

YOU CAN EITHER IMPORT THE FUNCTION AS "PAYMENT" OR CALL THAT FUNCTION WITH THE KEYWORD "ADD"

#SOLUTION 1

IMPORT AND EXPORT THE FUNCTION AS "PAYMENT"

IN hr.js

CHANGE

TO

module.exports = {payment}

IN main.js

CHANGE

TO

const { payment } = require("./hr.js")

#SOLUTION 2

CALL THE FUNCTION BY USING THE KEYWORD "ADD"

IN main.js

CHANGE

TO

console.log("your weekly payment is " + add(dev_type, hr))

console.log("your weekly payment is " + add(dev_type, hr));

COMMENT BELOW IF HAVING ANY DOUBTS


Related Solutions

I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
12) Can you please see that the calculations are correct, this is my 3rd try with...
12) Can you please see that the calculations are correct, this is my 3rd try with this same question and I've paid for every attempt. Thank you. A bicycle manufacturer currently produces 349,000 units a year and expects output levels to remain steady in the future. It buys chains from an outside supplier at a price of $1.90 a chain. The plant manager believes that it would be cheaper to make these chains rather than buy them. Direct in-house production...
can you check if my answers are correct and can you please type the correct answers...
can you check if my answers are correct and can you please type the correct answers for each question 5 points) Trevor is interested in purchasing the local hardware/electronic goods store in a small town in South Ohio. After examining accounting records for the past several years, he found that the store has been grossing over $850 per day about 60% of the business days it is open. Estimate the probability that the store will gross over $850 at least...
Windows PowerShell Scripting Please answer using a switch statement. I have asked this question already and...
Windows PowerShell Scripting Please answer using a switch statement. I have asked this question already and it was wrong. Thank you and I will upvote. 1) Write a PowerShell script that displays the total count of each type (dll, txt, log) of files in c:\windows using switch statement.
PLEASE READ CAREFULLY BEFORE STARTING THE ASSIGNMENT!!! AS YOU CAN SEE I AM DONE WITH ALMOST...
PLEASE READ CAREFULLY BEFORE STARTING THE ASSIGNMENT!!! AS YOU CAN SEE I AM DONE WITH ALMOST HALF THE TABLE. I DIDN'T FIND A SINGLE AMOUNT FOR THE COLUMNS: RENT EXPENSE, SALARIES EXPENSE, SUPPLIES EXPENSE, AUTO EXPENSE, MISC EXPENSE. THE SAME QUESTIONS HAS BEEN ASKED MANY TIMES ON CHEGG, BUT ALL THE AMOUNTS POSTED FOR THOSE MISSING COLUMNS ARE WRONG IN EACH AND EVERY SINGLE POST, SO PLEASE DON'T COPY AND PASTE FROM ANY OF THEM. I LITERALLY CHEKCED EACH AND...
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
Here is my fibonacci code using pthreads. When I run the code, I am asked for...
Here is my fibonacci code using pthreads. When I run the code, I am asked for a number; however, when I enter in a number, I get my error message of "invalid character." ALSO, if I enter "55" as a number, my code automatically terminates to 0. I copied my code below. PLEASE HELP WITH THE ERROR!!! #include #include #include #include #include int shared_data[10000]; void *fibonacci_thread(void* params); void parent(int* numbers); int main() {    int numbers = 0; //user input....
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT