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"));

12th May 2021, 10:48 AM
dheeraj gupta
dheeraj gupta - avatar
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"));
12th May 2021, 10:52 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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)
12th May 2021, 10:58 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Oh bcz the condition was false that's why loop is not working. Am I right?
12th May 2021, 10:55 AM
dheeraj gupta
dheeraj gupta - avatar
+ 1
A.S. Thanks.
12th May 2021, 11:00 AM
dheeraj gupta
dheeraj gupta - avatar
+ 1
Thanks Farnaz.A
13th May 2021, 5:57 PM
dheeraj gupta
dheeraj gupta - avatar