我的程序根据名称参数进行搜索。它有效,但结果不会出现,直到用户写Exit
结束循环。为什么结果显示在用户点击回车键的同一时刻?
var list = ['Drake', 'Nail', 'Gerd', 'Ahmed', 'Omar', 'Joe', 'Hadi', 'Felex'];
var search;
function printOut (IT) {
document.write('<p>' + IT+'</p>');
}
while (true) {
search = prompt(' if you want to know all the student write list, if you want to exit the programm write exit, and if you want to search about a student persenolly, write his name!!');
if (search === 'Exit') {
break;
} else if (search === 'list') {
document.write(list.join(', '));
break;
} else {
if (list.indexOf(search) > -1 ) {
printOut('yes,' + search + ' in our class!!')
} else {
printOut('no,' + search + 'is not in our class!!')
}
}
};