- 1
PLEASE HELP ME SOLVE MY PROBLEM (SOLVED)
How to push an element array to variable with for.. of loop, https://code.sololearn.com/WS3tvhNtWl8E/?ref=app
5 Answers
+ 4
https://code.sololearn.com/WElXdtf8oCF2/?ref=app
Explanation : for of loop to iterate over all elements of number, after each itration we check that (i%2) , i%2 will give eighter 1 or 0 , if it's 0 it means it's even and if it's 1 means it's odd and in javascript 0 is false and other numbers are true in if condition. So if i%2 is giving one means it's odd and 1 means true then it will push that element in odd.
0
you can also use filter() array method to do it onelined, as well as checking for oddity with using bitwise & operator:
let odd = number.filter(v => v&1);
& operator acts as a binary mask, returning only part of number wich have bits sets:
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
so n & 1 return left most bit of it: 0 or 1, wich means number is odd if 1 else even ^^
0
//print "JS is fun"
console.log("JS is fun")
- 3
Write a program to print "JS is fun".
Note that the sentence starts with capital letters.
Hint
Use console.log() function.
- 6
Write a program to print "JS is fun".
Note that the sentence starts with capital letters.
Hint
Use console.log() function.