0
Can we create a program for loop in which output is 1! 2! 3!
7 Respuestas
+ 2
Peter David Carter Yeah there are fancier ways. Also a oneliner is possible.
But I need Anant Mishra to at least show us his attempt, otherwise how would he learn?
+ 1
Ok
0
for(let i = 1; i < 4; i++) {
console.log(`${i}! `);
}
Is just one of many, many ways to do this. This one uses JavaScript ES6 interpolation, but you can also use the + concatenation operator if you need to support older browsers (assuming you are even coding for the web at all). In that case you'd also need to replace the let keyword with var, though you might find this problematic in terms of scoping.
You can also use Array(n) in JavaScript and iterate over the resulting array... though this creates holey arrays...
0
Are you using Python?
0
Yes
0
Can you show us your attempt?
0
Thomas Williams would you prefer to assist with the question? Python is not a first language and though I can write this in Python, if there are any fancier way to do it I'll be interested to find out.
Maybe we could see a simple example, and also something clever? So beginners and experienced devs both get something from the answer?