If the FedEx function does not receive a payment, it will need to return a value of Payment Required

I am struggling with understanding functions, parameters, and arguments in JavaScript as I am new to it.

My goal is to have a function that returns different values based on the payment amount. If no payment is passed, it should return "Payment Required", if the payment is less than 1000, it should return "Payment Insufficient", and if the payment is sufficient, it should return "OK".

    var shipping = function(letters, boxes, payment){

        if (payment < 1){
            return "Payment Required";
        }
        else if (payment < 1000) {
            return "Payment Insufficient";
        } 
        else {
            return "OK";
        }

    };

This code snippet defines the 'shipping' function.

    var delivery = function(letters, speed) {
        if (letters.length > 5){
            return shipping(letters, null, 1000);
        }
    };

    var sendMail = function(letter) {

        delivery([letter], "slow")

    };

    var shipping = function(letters, boxes, payment){

        if (payment < 1){
            return "Payment Required";
        }
        else if (payment < 1000) {
            return "Payment Insufficient";
        }
        else {
            return "OK";
        }

    };

However, I receive an error stating: "ReferenceError: fedEx is not defined"

Answer №1

Problems with the fedEx function were due to syntax errors: semicolons were removed after the conditional blocks, and "payments" was changed to "payment."

function fedEx(letters, boxes, payment) {
  if (!payment) {
    return "Payment Required";
  } else if (payment < 1000) {
    return "Payment Insufficient";
  }
  return "OK";
};

console.log(fedEx(0,0,null))
console.log(fedEx(0,0,0))
console.log(fedEx(0,0,100))
console.log(fedEx(0,0,1001))

Defining functions in this way allows for flexibility in ordering...

function fedEx(...) {...}

Instead of...

var fedEx = function(...) {...}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Canceling pending asynchronous actions in React/Redux: A step-by-step guide

Imagine the scenario where a user navigates to a page and two asynchronous Redux actions are dispatched simultaneously to fetch related sets of data. If one of these fetches fails, the component will detect it and render an error component on the next cycl ...

What is the best way to utilize MongoDB aggregate in this particular scenario?

How can I optimize this mongoose query to improve performance and reduce size for production? const currentYear = (new Date).getFullYear() const usedCars = await CarModel.find({ ModelYear: {$lte: currentYear - 1} }).limit(10) const recentCars = await Car ...

What is a unique method for creating a wireframe that replicates the structure of a square grid without using interconnected nodes

Currently, I am in the process of designing the wire frame styles for human body OBJs and my goal is to achieve a wire frame similar to the image below. In the following lines, you will find the code snippets that illustrate how I create the wire frame alo ...

Is it possible to conduct brain.js training sessions multiple times?

Is there a way to specifically train my neural network with new information without having to retrain the entire model, considering the potential performance costs associated with it? The neural network was created using brain.js. ...

What is the procedure for obtaining a Connect server's host name and port number?

Just like the example shown in this Express-related question, I'm wondering if there is a way to programmatically retrieve the host name and port number of a running Connect server? ...

What could be causing the callback function to not function correctly within the HOC component?

I am encountering an issue while passing the state (setActive) to the ButtonsOur component and then trying to pass it to the HOC through a callback. The error message "Uncaught TypeError: setActive is not a function" keeps popping up. Could you please help ...

The initial attempt to use autocomplete with Jquery UI is not functioning as expected upon entry

I'm facing a frustrating issue that's driving me crazy. I'm not an expert in javascript, but I believe the solution is simple. I'm using jQuery UI autocomplete with data retrieved from Ajax. The problem is, I only get the desired resul ...

Assistance is required to navigate my character within the canvas

Having trouble getting the image to move in the canvas. Have tried multiple methods with no success. Please assist! var canvas = document.getElementById("mainCanvas"); canvas.width = document.body.clientWidth; canvas.height = document.body.clientHeight; ...

Enhancing jQuery Functionality with Parameter Overrides

While it may seem like a simple question, I am new to writing jQuery plugins and could use some clarity on scope rules in JavaScript. My goal is to create a jQuery plugin that interacts with the Stack Overflow API. I have started exploring the Flair API f ...

Developing a Chrome browser extension tailored for parsing unique file formats

Currently, I am working on developing a compiler for a unique conditional formatting language. My aim is to enable the capability of opening files in my language directly in Chrome by simply double-clicking on them in File Explorer (I am currently using Wi ...

What is the alternative method of sending a POST request instead of using PUT or DELETE in Ember?

Is there a way to update or delete a record using the POST verb in Ember RESTAdapter? The default behavior is to send json using PUT or DELETE verbs, but those are blocked where I work. I was wondering if there's a way to mimic Rails behavior by send ...

The term 'undefined' does not refer to an object

My div contains the following code: <em id="ProductPrice" class="ProductPrice VariationProductPrice">$75.00</em> I want to change the text color if the value changes. This is what I tried: <script> $(document).ajaxSuccess(function(){ ...

Javascript - Conceal a Dynamic Div Depending on its Text

I have a unique table that generates dynamic Divs with ID's that count as they are created in the following format: <div id="dgpCheckDiv10_0"> <input Delete </div> <div id="dgpCheckDiv10_1"> text2 </div> Some of t ...

Is it appropriate for HTML5 Web Workers to utilize CORS for cross-origin requests?

As I was creating a hosted API that relies on web workers, I encountered an intriguing issue. I am looking for feedback from the community to help me with this. Even though my server has the necessary CORS headers in place to serve the worker JS files and ...

How can I make sure an animation only plays once during the current session?

I'm facing a dilemma with my website page that showcases animations using react-anime and react-typing-animation. The issue at hand is how to animate certain elements only once per session. In other words, if the main page animation triggers when the ...

Array updating using the foreach method in Angular

Hey everyone, I've encountered an error that seems to be related to scope and I could use some advice. I'm currently looping through an array and trying to push the results to another array. However, when I attempt to push the results to public m ...

Tips for sending information from an AJAX request to a Laravel 5.2 controller using the POST method

Hello everyone. I'm reaching out to the great community for some assistance with my first question here. I've recently started working with Laravel framework version 5.2 in a project of mine. My issue lies in trying to pass data using the post m ...

Having trouble implementing render props for a toggle button that reveals/hides child components

My goal is to display or hide a couple of child components based on a toggle click using the original HTML structure provided. However, I am encountering an issue where the EditToggle link needs to be displayed next to the h2 element inside the "subtitle-c ...

What causes the image to not appear at the center bottom of the page when using IE for loading?

Why does the loading image not appear at the center bottom of the page in IE? This function loads content when the page is loaded and also loads content when scrolled to the bottom. When you load the page index.php, you will see the loading image at the ...

Exploring objects as strings to retrieve data with Javascript

In a scenario where I receive an object of varying length that I do not control, I am required to extract specific data from it. The response I receive is in the form of a formatted string: { "questionId": 18196101, "externalQuestionId": "bcc38f7 ...