Return does not return a value, why?
-
Hello, I just started learning JS, so I don’t know some points. Here is a part of the code, my functions do not pass values back, but everything works. That is, I have a logic problem. They said to fix it using reassignment or alert, but nothing came of it. I also found nothing in the internet. Can someone explain what I did wrong and how to fix it? (
switch(operacia) { case "!" : {sorting (num1,num2, res2) alert (res2);} break; case "?" : { inverting (num1,num2, res2) alert (res2);} break; default: { alert ('C такой операцией мы не работаем'); } break; } function sorting (num1,num2) { var arr = num1.split(","); var arr2 = num2.split(","); var arr3 = arr.concat(arr2); res2 = arr3.sort(); return res2; } function inverting (num1,num2) { var arr = num1.split(","); var arr2 = num2.split(","); var arr3 = arr.concat(arr2); res2 = arr3.reverse(); return res2; }
JavaScript Anonymous, May 21, 2019 -
return works, you just need to assign the result somewhere. : thinking
const result = sorting (num1,num2);
alert (result);Anonymous -
function sorting has two arguments and is called with three. You can't do that.Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!