Document /*1.数据主体:包含6个订餐相关的数组 订餐人 names 送餐时间 dishmags 送餐时间 times 送餐地址 addresses 订单状态 states 总订单 sumPrices 包含3个菜品相关的数组 餐品名 dishNames 单价 prices 点赞数 praiseNums */ //订单信息 var names = ["小明", "小红"]; var disMegs = ["香辣鸡腿堡", "可乐"]; var times = [13, 14]; var addresses = ["江苏南京", "江苏南京"]; var states = [1, 0]; //是否预定 var sumPrices = [99 * 2, 52]; //餐品信息 var dishNames = ["香辣鸡腿堡", "薯条", "可乐", "全家桶"]; var prices = [18, 11, 8, 99]; var praiseNums = [78, 10, 8, 20]; //2.搭建框架结构 do { //使用ES6里面的模板字符串 //变量选择数字 var choice; // +prompt()接收录入的数据 +直接转换成整数 choice = +prompt(` ************************* 1.我要订餐 2.查看餐袋 3.签收订单 4.删除订单 5.我要点赞 6.退出系统 7.新品上架 ************************* 请选择: `); //根据选项进行操作 switch (choice) { case 1: console.log("====我要订餐===="); var yourName = prompt("请输入订餐人姓名") //展示菜品信息 console.log(`序号 菜名 单价 点赞数`); for (let i = 0; i < dishNames.length; i++) { //模板字符串解析变量 ${表达式} console.log(`${i + 1} ${dishNames[i]} ${prices[i]} ${praiseNums[i]}`); } //选择菜品编号 let youeDishNo = +prompt("请您选择要点的菜品编号"); while (youeDishNo > dishNames.length || youeDishNo < 1) { youeDishNo = +prompt("对不起,您点的菜真没有,请重新录入"); } // 选择份数 let yourChoiceCount = +prompt("请选择您需要的份数"); //拼接菜品信息 let yourDishMegs = dishNames[youeDishNo - 1] + " " + yourChoiceCount + "份" //选择时间 let yourTime = + prompt("请输入送餐时间(送餐时间10店到20点之间)"); while (yourTime > 20 || yourTime < 10) { yourTime = +prompt("对不起您录入的时间不在骑手的工作范围之内,请重新输入送餐时间"); } //选择地址 let yourAddress = prompt("请输入送餐地址"); //后台做计算价格 : (餐费大于50元免除配送费,否则配送费6元) //后台将订餐信息添加到数组中 //计算消费 let yourCash = prices[youeDishNo - 1] * yourChoiceCount > 50 ? 0 : 6; //三目运算符 //计算总价格 let yourTotalPrice = prices[youeDishNo - 1] * yourChoiceCount + yourCash; //将订餐信息添加到数组 names.push(yourName); disMegs.push(yourDishMegs); times.push(yourTotalPrice); //打印成功信息 console.log("订餐成功"); console.log(` --------------------------------------------------------------- 您订的是:${yourDishMegs} 送餐时间:${yourTime}点 餐费:${prices[youeDishNo - 1] * yourChoiceCount}元,送餐费:${yourCash}元,总计:${yourTotalPrice}元。 `); continue; case 2: console.log("****查看餐袋****"); console.log(`序号 订餐人 餐品信息 送餐日期 送餐地址 总金额 订单状态`); //let 块级作用域 定义的变量作用范围是离他最近的一个花括号的范围 for (let i = 0; i < names.length; i++) { console.log(`${i + 1}\t${names[i]}\t${disMegs[i]}\t ${times[i]}点 \t ${addresses[i]} \t${sumPrices[i]}元\t${states[i] == 0 ? '已预定' : '已签收'}`); } continue; case 3: console.log("****签收订单****"); let yourSignNo = +prompt("请选择要签收的订单序号"); //判断订单数组里面有没有数据 if (names.length === 0) { console.log("没有订单,输入错误"); } else { while (yourSignNo > names.length || yourSignNo < 1) { console.log("您选的订单不存在,请重新选择订单序号"); } //判断订单是否已签收,已签收不能再次签收给出提示 if (states[yourSignNo - 1] === 1) { console.log("您选择的订单已完成签收,不能再次签收!!!"); } else { //可以被签收,修改状态 states[yourSignNo - 1] = 1 console.log("签收完成,感谢您的配合"); } } continue; case 4: console.log("****删除订单****"); let yourDelNo = +prompt("请选择要删除的订单"); //判断订单数组里面有没有数据 if (yourDelNo === 0) { console.log("没有订单,输入错误"); } else { while (yourDelNo > names.length || yourDelNo < 1) { console.log("您选择的订单不存在,请重新输入订单号"); yourDelNo = +prompt("请选择要删除的订单"); } //判断订单是否已经删除,已删除 if (yourDelNo === 0) { console.log("订单未签收,不能删除"); } else { //将选择的订单从数组中删除 arry.splice(yourDelNo-1,1) //删除6个数组 let delNo = yourDelNo - 1; names.splice(delNo, 1); states.splice(delNo, 1); disMegs.splice(delNo, 1); sumPrices.splice(delNo, 1); addresses.splice(delNo, 1); times.splice(delNo, 1); console.log("删除成功,欢迎惠顾"); } } continue; case 5: console.log("****我要点赞****"); console.log("****我要点赞****"); console.log(`餐品信息 `); for (let i = 0; i < dishNames.length; i++) { console.log( `${i + 1}\t ${dishNames[i]}\t ${prices[i]}\t ${praiseNums[i] }\t` ); } let yourProductLikes = +prompt("请输入需要点赞的订单序号:"); //判断订单数组里面有没有数据 if (names.length === 0) { console.log("没有订单,输入错误!"); } else { while ( yourProductLikes > dishNames.length || yourProductLikes < 1 ) { console.log("您所选的订单不存在,诘重新订单序号:"); yourProductLikes = +prompt("请选择要签收的订单序号:"); } praiseNums.splice( yourProductLikes - 1, 1, ++praiseNums[yourProductLikes - 1] ); console.log("点赞成功"); for (let i = 0; i < dishNames.length; i++) { console.log( `${i + 1}\t ${dishNames[i]}\t ${prices[i]}\t ${praiseNums[i] }\t` ); } } continue; case 6: console.log("****退出系统****"); break; case 7: console.log("***新品上架****"); console.log(`餐品信息`); for (let i = 0; i < dishNames.length; i++) { console.log(`${i + 1}\t ${dishNames[i]}\t ${prices[i]}\t ${praiseNums[i]}`); } var yourNewChoices = prompt("请输入需要的订单名称:"); var yourNewPrices = +prompt("请输入需要的订单价格:"); var yourdianzan = 0; dishNames.push(yourNewChoices); prices.push(yourNewPrices); praiseNums.push(yourdianzan); console.log("添加成功"); for (let i = 0; i < dishNames.length; i++) { console.log(`${i + 1}\t ${dishNames[i]}\t ${prices[i]}\t ${praiseNums[i]}`); } continue; } //跳出系统 break; } while (true) console.log("程序结束");
<!DOCTYPE html><html lang=“en”>
<meta charset=“UTF-8”> <meta http-equiv=“X-UA-Compatible” content=“IE=edge”> <meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
/*1.数据主体:包含6个订餐相关的数组 订餐人 names 送餐时间 dishmags 送餐时间 times 送餐地址 addresses 订单状态 states 总订单 sumPrices
包含3个菜品相关的数组 餐品名 dishNames 单价 prices 点赞数 praiseNums */
//订单信息 var names = [“小组长”, “王军威”]; var disMegs = [“大肉丸子2个”, “鸡1只”]; var times = [13, 14]; var addresses = [“江苏警官学院”, “江苏警官学院”]; var states = [1, 0]; //是否预定 var sumPrices = [99 * 2, 52];
//餐品信息 var dishNames = [“大肉丸子”, “鸡”, “鸭屁股”, “烤乳猪”]; var prices = [99, 52, 9.9, 13]; var praiseNums = [78, 10, 8, 20];
//2.搭建框架结构 do { //使用ES6里面的模板字符串 //变量选择数字 var choice; // +prompt()接收录入的数据 +直接转换成整数 choice = +prompt(`
*************************
1.我要订餐 2.查看餐袋 3.签收订单 4.删除订单 5.我要点赞 6.退出系统 7.新品上架
*************************
请选择:
`);
//根据选项进行操作 switch (choice) { case 1: console.log(“====我要订餐====”); var yourName = prompt(“请输入订餐人姓名”) //展示菜品信息 console.log(`序号 菜名 单价 点赞数`); for (let i = 0; i < dishNames.length; i++) { //模板字符串解析变量 ${表达式} console.log(`${i + 1} ${dishNames[i]} ${prices[i]} ${praiseNums[i]}`); }
//选择菜品编号 let youeDishNo = +prompt(“请您选择要点的菜品编号”); while (youeDishNo > dishNames.length || youeDishNo < 1) { youeDishNo = +prompt(“对不起,您点的菜真没有,请重新录入”); }
// 选择份数 let yourChoiceCount = +prompt(“请选择您需要的份数”);
//拼接菜品信息 let yourDishMegs = dishNames[youeDishNo – 1] + ” “ + yourChoiceCount + “份”
//选择时间 let yourTime = + prompt(“请输入送餐时间(送餐时间10店到20点之间)”); while (yourTime > 20 || yourTime < 10) { yourTime = +prompt(“对不起您录入的时间不在骑手的工作范围之内,请重新输入送餐时间”); }
//选择地址 let yourAddress = prompt(“请输入送餐地址”);
//后台做计算价格 : (餐费大于50元免除配送费,否则配送费6元) //后台将订餐信息添加到数组中 //计算消费 let yourCash = prices[youeDishNo – 1] * yourChoiceCount > 50 ? 0 : 6; //三目运算符
//计算总价格 let yourTotalPrice = prices[youeDishNo – 1] * yourChoiceCount + yourCash;
//将订餐信息添加到数组 names.push(yourName); disMegs.push(yourDishMegs); times.push(yourTotalPrice);
//打印成功信息 console.log(“订餐成功”); console.log(` ————————————————————— 您订的是:${yourDishMegs} 送餐时间:${yourTime}点 餐费:${prices[youeDishNo – 1] * yourChoiceCount}元,送餐费:${yourCash}元,总计:${yourTotalPrice}元。
`); continue;
case 2: console.log(“****查看餐袋****”); console.log(`序号 订餐人 餐品信息 送餐日期 送餐地址 总金额 订单状态`); //let 块级作用域 定义的变量作用范围是离他最近的一个花括号的范围 for (let i = 0; i < names.length; i++) { console.log(`${i + 1}\t${names[i]}\t${disMegs[i]}\t${times[i]}点 \t${addresses[i]}\t${sumPrices[i]}元\t${states[i] == 0 ? ‘已预定’ : ‘已签收’}`);
} continue;
case 3: console.log(“****签收订单****”); let yourSignNo = +prompt(“请选择要签收的订单序号”); //判断订单数组里面有没有数据 if (names.length === 0) { console.log(“没有订单,输入错误”); } else { while (yourSignNo > names.length || yourSignNo < 1) { console.log(“您选的订单不存在,请重新选择订单序号”); } //判断订单是否已签收,已签收不能再次签收给出提示 if (states[yourSignNo – 1] === 1) { console.log(“您选择的订单已完成签收,不能再次签收!!!”); } else { //可以被签收,修改状态 states[yourSignNo – 1] = 1 console.log(“签收完成,感谢您的配合”); } }
continue;
case 4: console.log(“****删除订单****”); let yourDelNo = +prompt(“请选择要删除的订单”); //判断订单数组里面有没有数据 if (yourDelNo === 0) { console.log(“没有订单,输入错误”); } else { while (yourDelNo > names.length || yourDelNo < 1) { console.log(“您选择的订单不存在,请重新输入订单号”); yourDelNo = +prompt(“请选择要删除的订单”); } //判断订单是否已经删除,已删除 if (yourDelNo === 0) { console.log(“订单未签收,不能删除”); } else { //将选择的订单从数组中删除 arry.splice(yourDelNo-1,1) //删除6个数组 let delNo = yourDelNo – 1; names.splice(delNo, 1); states.splice(delNo, 1); disMegs.splice(delNo, 1); sumPrices.splice(delNo, 1); addresses.splice(delNo, 1); times.splice(delNo, 1); console.log(“删除成功,欢迎惠顾”); } } continue;
case 5: console.log(“****我要点赞****”); console.log(“****我要点赞****”); console.log(`餐品信息 `); for (let i = 0; i < dishNames.length; i++) { console.log( `${i + 1}\t${dishNames[i]}\t${prices[i]}\t${praiseNums[i] }\t` ); } let yourProductLikes = +prompt(“请输入需要点赞的订单序号:”); //判断订单数组里面有没有数据 if (names.length === 0) { console.log(“没有订单,输入错误!”); } else { while ( yourProductLikes > dishNames.length || yourProductLikes < 1 ) { console.log(“您所选的订单不存在,诘重新订单序号:”); yourProductLikes = +prompt(“请选择要签收的订单序号:”); }
praiseNums.splice( yourProductLikes – 1, 1, ++praiseNums[yourProductLikes – 1] ); console.log(“点赞成功”); for (let i = 0; i < dishNames.length; i++) { console.log( `${i + 1}\t${dishNames[i]}\t${prices[i]}\t${praiseNums[i] }\t` ); } }
continue;
case 6: console.log(“****退出系统****”);
break;
case 7: console.log(“***新品上架****”); console.log(`餐品信息`); for (let i = 0; i < dishNames.length; i++) { console.log(`${i + 1}\t${dishNames[i]}\t${prices[i]}\t${praiseNums[i]}`); }
var yourNewChoices = prompt(“请输入需要的订单名称:”); var yourNewPrices = +prompt(“请输入需要的订单价格:”); var yourdianzan = 0;
dishNames.push(yourNewChoices); prices.push(yourNewPrices); praiseNums.push(yourdianzan);
console.log(“添加成功”); for (let i = 0; i < dishNames.length; i++) { console.log(`${i + 1}\t${dishNames[i]}\t${prices[i]}\t${praiseNums[i]}`); } continue;
} //跳出系统 break;
} while (true) console.log(“程序结束”);