0

Why wont this code run

function multiply(a, b){ a * b }

21st Feb 2017, 7:10 PM
Micah
Micah  - avatar
8 Respostas
+ 9
Use console.log for output or return function multiply(a, b){ console.log(a * b); return a * b; }
21st Feb 2017, 7:13 PM
Roger C
Roger C - avatar
+ 1
@micha rogers explaination would be a perfect way to do it. you could also use a local variables and multiply them that way too. that would be the long way i guess lol
21st Feb 2017, 7:20 PM
Robin
Robin - avatar
+ 1
does anyone knows how to solve this and why? waiting for javascript ninjas here! You will be using JavaScript to write a simple function that can accomplish a goal. We want to find the credit card number whose digits sum to the largest number. If more than one has the same largest sum of digits, we want the last one in the list with that sum. Write a single function that takes one argument. That argument will be an array of credit card numbers. Assume the array can have any number of credit card numbers and each one is a string of digits and dashes. Your function should return the credit card number that has the largest sum of digits. Here is a sample array of credit card numbers: ['4916-2600-1804-0530', '4779-252888-3972', '4252-278893-7978', '4556-4242-9283-2260'] In the sample array above, the digits add up to 49, 81, 81, and 64 respectively. Since there are two which have the same sum, the function should return the last one with that sum, in this case '4252-278893-7978' Start by thinking through your step-by-step process. Then, submit your best code. If your code isn't complete, that's OK; just let us know how far you were able to get. What do you need to do to solve this problem? Explain your thought process and how you will work through each part.
31st Aug 2017, 8:09 PM
Don Aldrich Tamayo
Don Aldrich Tamayo - avatar
+ 1
Looks like this is one of the challenges for Code Wars: https://www.codewars.com/ Answered this one previously here: https://www.256kilobytes.com/index.php/content/show/2081/javascript-why-does-this-code-not-work-correctly-code-function-multiply-a-b-a-b The solution is that the function is missing the "return" keyword. The code runs, but returns nothing (i.e., undefined).
12th Jan 2019, 9:00 AM
August R. Garcia
August R. Garcia - avatar
+ 1
Because you need to return the value. So the answer looks like this : function multiply(a, b){ return a * b } multiply(4,5);
28th Jul 2019, 5:56 PM
Manab Das
Manab Das - avatar
0
This code can run : function multiply(a, b){ var c = a * b; console.log(c); // or alert(c) and .... } multiply(2,3); because: 1. you never call that function. 2. you only multiply 2 variable and never say where should show re result
22nd Feb 2017, 1:00 PM
Soroush Ebadi
Soroush Ebadi - avatar
0
help me I am stuck on this one
22nd Apr 2019, 10:45 PM
Anthony
0
function multiply(a, b){ return a * b } const math = multiply(4, 5) console.log(math)
30th Jan 2020, 9:52 PM
mikeStrickland