I want to have a logic where if I enter an even number I want next 10 even numbers to be printed and If I enter an odd number, I want next 10 odd numbers to be printed. How should I rectify this logic inside a function. If someone can please help me rectifying the logic which was answered.
JS
function oddEven() {
var input = prompt("");
for (let x = 1; x <= 10; x ) {
console.log(input x * 2);
}
}
oddEven()
CodePudding user response:
This should work for any number
const input = 2
for (let x = 1; x <= 10; x = 1) {
console.log(input x * 2)
}
CodePudding user response:
let inputval = 2;
for (let x=1; x<=10; x ) {
console.log(inputval x * 2)
}
CodePudding user response:
i hope this help
function printTen(input){
let list = []
let number = input
while(list.length <= 10){
number
if(input % 2 === 0 && number % 2 === 0){
console.log(number " is even");
list.push(number)
}else if(input % 2 !== 0 && number % 2 !== 0) {
console.log(number " is odd");
list.push(number)
}
}
}
printTen(9)