# I need help with javascript

Hey guys please help me #Write a loop in JavaScript that will display all even numbers in the console between 0 and "nb". In the example below, the variable "nb" is equal to 15.

4/10/2021 4:09:22 PM

ABDELJALIL ESSOUALHI36 Answers

New AnswerABDELJALIL ESSOUALHI Have you tried this yourself? If you have, please show us your attempt. You are more likely to get help when you post your attempt and ask a specific question, rather than something like "please help me do this whole task".

for (var x=0; x<=15; x++) { if (x === 0) { console.log(x + " is even"); } else if (x % 2 === 0) { console.log(x + " is even"); } else { console.log(x + " is odd"); } }

If all you need to do is display even numbers and you don't care about odd ones, you can do this: for (let x=0; x<15; x+=2) { console.log(x + " is even"); } Just replace 15 with your variable nb to make it work for any value.

Is this work too ? var nb = 15; for (var x=2; x<=nb; x+=2) { console.log(x); }

ABDELJALIL ESSOUALHI that will ignore 0. So if you want to get 0 as an even number too, change var x = 2 to var x = 0. Also, x <= nb will include the nb value as well if it's even. For example, if nb was 16 you would get 16 printed out too. If you want only numbers up to nb but exclude nb, change to x < nb.

Here i just ran a loop where i checked if a number is even by checking if it had a reminder when divided by 2(if it doesn't have a reminder it's even) and then i displayed that number that didn't have a reminder.The output in this case will be 2,4,6,8,10,12,14.Hope this helped. var nb=15; for(var i=1; i<nb; i++){ if(i%2==0){ console.log(i); } } P.S. 'i' is equal to 1,because if it were equal to 0, then the output would be 0,2,4,6,8,10,12,14, which i think is incorrect.

/* try this code; this is important for beginners to understand */ let n = prompt ("Find even numbers upto what number", 14); let x; for(x = 0; x <= n; x++){ if ( x % 2 === 0 && x != 0 ){ console.log(x); } }

/* this should work. but not tested. */ var nb = prompt("even nums from 0 to your answer:"); for(var a = 0; a <= nb; a += 2){ console.log(a); }

for (var x=0; x<=15; x++) { if (x % 2 === 0) { console.log(x + " is even"); } else { continue; } }

function number(nb) { console.log('even numbers are') for(let i = 0; i<=nb; i+=2) { console.log(i); } } const myInput = 15; const numbers = number(myInput);

Explanation: It will take 150/40 = 3.75 hours to cover the distance, which is equivalent to 3.75*60 = 225 minutes. How i solve it

Hey guys please help me #write JavaScript loop that accepts a positive integer n from the keyboard through text box and calculate the sum of square of even digital

The code to display all even numbers in console between 0 and nb should be: //code for (let i = 0; i < nb; i+=2){ console.log(i) } Replacing nb with the desired number or declaring a variable nb which stored the number will make it work.