Javascript- Multiplying 2 Numbers and Return Number

I normally have understood this stuff well as I am taking web programming for a non-major class and guess I am just a little confused on what I'm being asked to do.

I am told to "Write a function named "MULTIPLY" that accepts 2 parameters. the function will be declared this way:

function MULTIPLY(parameter1, parameter2){
    //The parameter names can be whatever you want 
    //Your code goes here

};

I have wrote this as my code :

function MULTIPLY (price, shipping) {
    return price*shipping;

    enter code here

    product=number1*number2;

    //return the result

    return total;
1

2 Answers

<script>
    function multiplyNumbers(x,y){
        return x*y;
    }
    var z= multiplyNumbers(4,5); // Function is called, return value will end up in z

</script>
<button onclick="document.getElementById('multiplication').innerHTML=z;">Multiply numbers</button>
<p id="multiplication"></p>

You have a few problems. Here is how it should look

function MULTIPLY(price, shipping) {
    //Return the sum
    return price*shipping;
}

//Call MULTIPLY to multiply the two numbers
var product=MULTIPLY(number1, number2);
7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest