结果仅在循环退出后出现

时间:2016-09-16 10:25:15

标签: javascript

我的程序根据名称参数进行搜索。它有效,但结果不会出现,直到用户写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!!')
        }
    }
};

0 个答案:

没有答案