function main() {
var dayofWeek = readLine();
var quietRules = 'mowing, hanging out laundry, washing a car, recycling bottles are not allowed';
if (dayofWeek) {
console.log('mowing, hanging out laundry, washing a car, recycling bottles are not allowed');
}
您可以使用switch语句。
switch (dayOfWeek) {
case "Sunday":
console.log('mowing, hanging out laundry... etc')
case "Monday":
console.log('make coffee, commute to work... etc')
default:
console.log('wake up, eat')
}
注意,默认情况类似于";否则";switch语句的。
还有另一种方法可以做到这一点;规则";一周中的某一天发生变化。
var quietRules = {
"Sunday": "mowing, hanging out etc..."
"Monday": "working, excercise"
}
if(dayOfWeek) {
console.log(quietRules[dayOfWeek])
}
我建议您检查文档,但有一个简单的例子。
if(dayofWeek === "Sunday")
{
console.log('mowing, hanging out laundry, washing a car, recycling bottles are not allowed');
}