How do I write a loop, typing a loop from the keyboard, aborting after typing "& amp;"?
-
Organize cyclic input from the keyboard of elements that will be added to the existing array A = [1,2,3] at the end. Provide a termination character "& amp;"
I wrote a code like this, it does not stop entering data after entering "& amp;"
var arr = [1, 2, 3,];
for (var i = 2; i & lt; arr.length; i ++) {
if (i! == '& amp;') {
arr.push (prompt ('Lead'));
}
else {
break;
}
}
console.log (arr);JavaScript Clare Abbott, May 21, 2020 -
for(var i = 2; i < arr.length; i++){
if(i !== '&'){ // i это счетчик
arr.push( prompt('Ведите')); // значение prompt нигде не проверяется
}
const arr = [1,2,3]
while (true) {
const input = prompt('hi')
if (input === '&') break
arr.push(input)
}
console.log(arr)Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!