0

Can we create a program for loop in which output is 1! 2! 3!

19th Sep 2019, 7:15 AM
Anant Mishra
Anant Mishra - avatar
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?
19th Sep 2019, 7:35 AM
Trigger
Trigger - avatar
+ 1
Ok
19th Sep 2019, 7:35 AM
Anant Mishra
Anant Mishra - avatar
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...
19th Sep 2019, 7:26 AM
Peter David Carter
Peter David Carter - avatar
0
Are you using Python?
19th Sep 2019, 7:29 AM
Trigger
Trigger - avatar
0
Yes
19th Sep 2019, 7:30 AM
Anant Mishra
Anant Mishra - avatar
0
Can you show us your attempt?
19th Sep 2019, 7:31 AM
Trigger
Trigger - avatar
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?
19th Sep 2019, 7:32 AM
Peter David Carter
Peter David Carter - avatar