256 Kilobytes

Answers in Client-Side | By Some Guy

Published 5 months agoFri, 11 Jan 2019 23:40:27 -0800 | Last update 5 months agoFri, 11 Jan 2019 23:56:13 -0800

818 views, 0 RAMs, and 1 comment

Profile Photo - Some Guy Some Guy
🗎 3224 🗨 41 🐏 31

Dear sirs,

Please help. My code--shown below--is not working how I would expect. Does anyone know how to fix this?

// Define the function
function multiply(a, b){ a * b }

// Call the function
var x = 10;
var y = 3;
var z = multiply(x, y);

// Show the result. Should show "30" but instead shows "undefined"

Thanks in advance.

Edit: For reference, this seems to be one of the challenges on Code Wars, which you can find more of if you follow that link.

Download more RAM. 🐏 ⨉ 0 Posted by Some Guy 5 months ago

Edit History

• [2019-01-11 23:40 PST] Some Guy (5 months ago)
🕓 Posted at 11 January, 2019 23:40 PM PST

This is a patsy account used by the 256 Kilobytes staff to seed content. 

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 149 🗨 769 🐏 211
Site Owner

The function should state "return a * b;" instead of "a * b;"

// Define the function
function multiply(a, b){ return a * b; }

// Call the function
var x = 10;
var y = 3;
var z = multiply(x, y);

// Shows "30" 

The "return" keyword is what makes a value get passed out of the function and back to the "z" variable. Without it, the function just ends.

From the Mozilla Web Docs:

When a return statement is used in a function body, the execution of the function is stopped. If specified, a given value is returned to the function caller. For example, the following function returns the square of its argument, x, where x is a number.

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return

Users Who Have Downloaded More RAM:
JJJJJ (1 month ago)
🐏 ⨉ 1
Posted by August R. Garcia 5 months ago

Edit History

• [2019-01-11 23:47 PST] August R. Garcia (5 months ago)
🕓 Posted at 11 January, 2019 23:47 PM PST

Sir, I can do you a nice SEO.

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.