0
Print character of odd position given a string using JavaScript?
in JavaScript
4 ответов
+ 2
explain?
+ 1
ooh i get it! also that is c++ and not js but the code is simple!
var chars = "123456789";
for(i=0;i<chars.length;i++) {
if(parseInt(chars[i])%2!==0) {
console.log(parseInt(chars[i]));
}
}
0
using js.! not c++? plz explain
- 1
str = "0123456"
for(var I = 0; I < str.length; I++){
if(I%2!=0){ //check if odd using modulus
cout<<I<<" = "<<str[I]<<endl;
}
}
output:
1
3
5