Nested If Else Statements

You don’t like waking up every morning and thinking about how you’re going to spend your day. As as result, you write a program that tells you what to do. 

Write a function called decide that takes a string containing the day of the week and another string containing the weather, and returns a string telling you how to spend your day. If it is a weekday, return “go to work or school”. If it’s a weekend, check if it’s "rainy" or if it is "sunny". If it’s sunny, return “go outside” and it if it’s raining, return “go code”. 

Use the isWeekday(day) function to check if it is a weekday or weekend.

/*This function returns true if the day is a weekday, and
false if it is a weekend. For example, isWeekday(“Monday”)
returns true.*/

function isWeekday(day) {
return day == “Monday” || day == “Tuesday” || day == “Wednesday” || day == “Thursday” || day == “Friday”;
}

function decide(day, weather) {

var weekdayPlan = “go to school or work”;
var rainyWeekend = “go code”;
var sunnyWeekend = “go outside”;

//Complete the function body below to return an activity depending on the day and weather.
}

//This is just for you to see what happens when the function is called
console.log(decide(“Monday”, “sunny”));

Advertisements

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s