0
Why wont this code run
function multiply(a, b){ a * b }
8 Respostas
+ 9
Use console.log for output or return
function multiply(a, b){
console.log(a * b);
return a * b;
}
+ 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
+ 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.
+ 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).
+ 1
Because you need to return the value. So the answer looks like this :
function multiply(a, b){
return a * b
}
multiply(4,5);
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
0
help me I am stuck on this one
0
function multiply(a, b){
return a * b
}
const math = multiply(4, 5)
console.log(math)