+ 1

Can you make it shorter?? JS

Presentation should be same https://code.sololearn.com/Ws1GmfIjDLAJ/?ref=app

8th Nov 2021, 4:24 PM
Himansh
Himansh - avatar
5 Answers
+ 2
Himansh this might be shorter and it follows the maximum condition as well. let a = ['1st','2nd','3rd','4th','5th'], r = 1, i = prompt ("How many times you want to show alert message (max: 5)") while (r <= a.length && r <= i){ alert(a[r-1]) ++r }
8th Nov 2021, 5:04 PM
Art1mis
+ 3
Himansh Use array instead of Hard Code checking var arr = ['1st', '2nd', '3rd', '4th', '5th']; for (let r = 1, i = prompt("How many times you want to show alert message (max:5)"); r <= i; r++) { alert(arr[r - 1]); };
8th Nov 2021, 4:44 PM
A͢J
A͢J - avatar
+ 2
for (let r=1, i=prompt("How many times you want to show alert message (max:5)"); r <= i && r <= 5; r++) alert(['1st', '2nd', '3rd', '4th', '5th'][r-1]);
8th Nov 2021, 9:12 PM
SoloProg
SoloProg - avatar
+ 2
I worked with the code and made this https://code.sololearn.com/WYaWVEXb1oo3/?ref=app
9th Nov 2021, 1:50 PM
Ski3r3n
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Art1mis Both answers are really to the point and I don't think there may be more shorter way to do so! 👍
8th Nov 2021, 5:14 PM
Himansh
Himansh - avatar