0
What's wrong with this code?
function fun(str) { var abc=str.split(""); var jkl=""; for(var i=abc.length-1;i=0;i--){ jkl.push(abc[i]); } return jkl; } console.log(fun("abcd"));
8 Respostas
+ 2
There is mistake in your loop Second place of condition u written i=0 here u should write condition
i>0
function fun(str) {
var abc=str.split("");
var jkl="";
for(var i=abc.length-1;i>0;i--){
jkl.push(abc[i]);
}
return jkl;
}
console.log(fun("abcd"));
+ 2
dheeraj gupta exactly and also error was you have to write conditions and here u trying to assigning values I don't know much more about js but in c cpp java its error u can not assign values becz the syntex of loop is
For(initialisation; condition; incremet decrement)
+ 1
Oh bcz the condition was false that's why loop is not working. Am I right?
+ 1
A.S. Thanks.
+ 1
Thanks Farnaz.A