How do i partition inputed integers of about 5 or more entries, since i want to return or display the input. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do i partition inputed integers of about 5 or more entries, since i want to return or display the input.

var x = prompt("Enter a number”); if (p>=5). For example inputing 123455 will return 123455 and what i want is 1, 2, 3, 4, 5, 5.

22nd Sep 2018, 3:04 PM
Omotesho Olusegun
Omotesho Olusegun - avatar
3 Answers
+ 2
Omotesho Olusegun, You need to push your input from prompt(String) to a new array(Object). What it does is it pushes the string into the array and creates for every character/number a new array element. Hope this helps👍 var input = prompt(), num = [], len = input.length; for (let i=0; i<len; i++){ num.push(' '+input[i]); } console.log(typeof num+"\n"+typeof input+"\n"+num); Have look at the code snippet👍 https://code.sololearn.com/Wc0Z77by24tu/?ref=app
22nd Sep 2018, 3:17 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 2
Omotesho Olusegun, I modified the code to work with multiple input. This way you avoid having multiple prompt popups There are 3 input tags available to insert your numbers. Have a look at the changes👍 https://code.sololearn.com/WZIxdB2e7GF1/?ref=app
22nd Sep 2018, 3:54 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
0
thanks for this. i successfully use the ".push" for multiple use of the prompt command. So i want to avoid going thru many "prompt" command. I hope this work for multiple digit integes.
22nd Sep 2018, 3:28 PM
Omotesho Olusegun
Omotesho Olusegun - avatar