javascript - display next weekday only after asking
问题描述
I have some problem understanding how to resolve this. Loop the output of days of the week like this: "Day of the week. Do you want to see the next day?" And so on as long as the user clicks OK.
var a = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var again = false;
do {
var question = prompt("Do you want to see the next day? (Yes / No)");
if (question == 'Yes') {
array();
var question;
again = true;
break;
}
} while (!again);
function array() {
for (i = 0; i < a.length; i++) {
console.log(a[i]);
}
}
解决方案
You should check the real console to see the output step by step.
Stackoverflow does not output step by step.
var idx = 0;
var a = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var again = false;
while (true) {
var question = prompt("Do you want to see the next day? (Yes / No)");
again = (question == 'Yes');
if (again) {
idx++;
console.log(a[idx]);
} else {
break;
}
}
推荐阅读
- c++ - 非类型模板参数类型随机变化
- casting - 如何将字符串转换为 uint32 luajit ffi
- matlab - 扭矩 Simulink 模型到脚本文件
- java - 尝试在 Android 活动中执行简单命令时出错
- c - ALSA - 非阻塞(交错)读取
- javascript - HighCharts - 为只有单个数据点的系列启用标记?
- python - 在文档开头添加注释
- php - xdebug - php 5.2.6/xampp/zend 的 v2.2.5 和 v2.5.5 出现超时错误和无法加载错误
- mysql - 主从复制不工作但状态正常
- android - 如何使用 OkHttpClient 在 Kitkat 上下载 apk 文件