I have a problem that i want to solve without using an array
Print the numbers from 1 to 100. If the number is divisible by 10, print "Hello"
Code
Array.from(Array(100), (_,i) => console.log(i+1));
Using for loop:
for(let i = 1; i <= 100; i++) {
console.log(i);
if(i % 10 === 0) console.log("Hello");
}
A little more edits to your current solution
Array.from({ length: 100 }, (_, i) =>
console.log(i + 1, (i + 1) % 10 === 0 ? "Hello" : "")
)
To be more concise do this:
Array(100).fill().map((_, i) => console.log((i + 1) % 10 === 0 ? "hello" : i + 1))