I want to take an user input that determins the number of inputs desired to take & input that number of inputs . For example if i need to enter 5 inputs ,the user would get a prompt asking what number of inputs you want to enter & if i log it and continue the the user gets another prompt asking the inputs
Asked
Active
Viewed 292 times
-1
-
[This page describing HackerRank challenges](https://codeburst.io/solving-challenges-from-hackerrank-using-javascript-part-3-9ba247163e8e) explains the technique you're describing. – Robert Harvey May 19 '20 at 16:25
-
Can you show us what you have tried so far? And please narrow your question down to a specific language/framework since it will greatly impact the answer. – jBuchholz May 19 '20 at 16:55
2 Answers
0
You can use something like this for python and use the list as you want
lst = []
n = int(input("Enter number of elements : "))
for i in range(0, n):
ele = int(input())
lst.append(ele) # adding the element
print(lst) #lst will contain all user inputs
For Javascript
var lst = [];
var n = prompt("Enter number of elements : ");
var ele;
for(let i = 0; i < n; i++){
ele = prompt("");
lst.push(ele); # adding the element
}
console.log(lst); #lst will contain all user inputs

shubhamwadhwa12
- 21
- 2
0
In javascript
let numbersOfInputs = 1 * prompt('Enter the total numbers of input',0);
let inputAsArray = [] ;
for(let index = 0;index < numbersOfInputs;index += 1){
let temp = 1 * prompt(`Enter the value for inputAsArray[${index}]`,0);
inputAsArray.push(temp);
};
console.log(inputAsArray)

SUDHIR KUMAR
- 381
- 4
- 10