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

Can you please check my answers and if I am wrong correct me. Thank you! A....
Can you please check my answers and if I am wrong correct me. Thank you! A. In today's interconnected world, many central banks communicate regularly and frequently with the public about the state of the economy, the economic outlook, and the likely future course of monetary policy. Communication about the likely future course of monetary policy is known as "forward guidance.". If the central bank increases the reserve ratio, as the market has perfectly expected, which of the following will...
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...
I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
Getting an error with my for loop.  How do I correct it?  I am supposed to: Continuously prompt...
Getting an error with my for loop.  How do I correct it?  I am supposed to: Continuously prompt for the number of minutes of each Rental until the value falls between 60 and 7,200 inclusive. For one of the Rental objects, create a loop that displays Coupon good for 10percent off next rental as many times as there are full hours in the Rental. ///////////////////////////////RentalDemo package java1; import java.util.Scanner; public class RentalDemo { public static void main(String[] args) {    Rental object1 =...
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...
In the following code down below I am not getting my MatrixElementMult right. Could someone take...
In the following code down below I am not getting my MatrixElementMult right. Could someone take a look at it and help fix it? Also, when I print out the matrices I don't want the decimals. I know it's a format thing but I'm new to C and not getting it. Thanks! #include <stdlib.h> #include <stdio.h> #include <math.h> #define N 8 typedef struct _Matrix { double element[N][N]; } Matrix; void PrintMatrix(Matrix a){ int i,j; for(i=0;i<N;i++){ for(j=0;j<N;j++){ printf(" %.1f ",a.element[i][j]); }...
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...
Hi I am getting error in implement some test case using Java. I am adding my...
Hi I am getting error in implement some test case using Java. I am adding my code and relevant files here, and the failed test. Please let me know where my problem is occuring and fix my code. Thanks! I will upvote. Implement a class to perform windowing of a Hounsfield value Implement the class described by this API. A partial implementation is provided for you in the eclipse project; however, unlike the previous class, very little work has been...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT