The select variable returns as a string. Hence,
select === 1 // always false
select === '1' // works as expected
Modified Source:
var options = [
"ET",
"Schindler’s List",
"Up",
"What’s Eating Gilbert Grape",
];
var process = function() {
while (options.length > 1) {
for (var i = options.length-1; i >= 1; i--) {
var select = prompt("VETO one of the following: 1. " + options[i] + " 2. " + options[i-1]);
if (select === '1') { // changed
options.splice(i, 1);
}
else {
options.splice(i-1, 1);
}
}
}
};
process();
alert(options);
Also, use var
to declare variables - always.