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...
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...
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...
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...
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.
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;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT