JavaScript新增學生信息
阿新 • • 發佈:2018-05-27
code ++ test 使用 rip div java cti ()
function add(user1, length) { let status = true; //狀態值 console.log("請輸入新增學生姓名:"); let name = readline.question(); let reg1 = /[a-zA-Z]/; //使用正則表達式來確保學生姓名輸入正確 while (!reg1.test(name)) { console.log("學生姓名不得包含數字和非法字符,請重輸"); name = readline.question(); } console.log("請輸入新增學生年齡:"); let age = readline.question() - 0; while (isNaN(age) || age < 1) { //保證輸出正確年齡 console.log("請重輸"); age = readline.question() - 0; } console.log("請輸入新增學生性別:"); let gender = readline.question(); console.log("請輸入新增學生成績:"); let score = readline.question() - 0;while (isNaN(score) || score < 0 || score > 100) { //保證輸出正確成績 console.log("請重輸"); score = readline.question() - 0; } console.log("新增成功! 該學生信息如下:"); length++; user1.push({ id: length, name, age, gender, score }) console.log(user1[length- 1]); } add(user1, user1.length);//調用函數
JavaScript新增學生信息