Why function "return UNDEFINED" ? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Why function "return UNDEFINED" ?

var str = prompt(); var arr = str.split(''); var num = arr.length; for (var k=0;k<=num;k++) { var x = arr[k]; document.write(getString(x)); } function getString(x){ var div = document.createElement("div"); div.className = "className"; var oText = document.createTextNode(x); div.appendChild(oText); document.body.appendChild(div); }

12th Mar 2019, 4:28 PM
misha
2 Respuestas
+ 2
// Because "x" is a variable parameter and he must need a "return" keyword to show the value of this variable, otherwise, he doesn't work.
12th Mar 2019, 7:38 PM
program
program - avatar
+ 1
Because you haven't defined a return value at the end of your function.
12th Mar 2019, 4:58 PM
HonFu
HonFu - avatar