Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@colevandersWands
Created April 21, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colevandersWands/425b3125ce3e00ed25dfe727624b528c to your computer and use it in GitHub Desktop.
Save colevandersWands/425b3125ce3e00ed25dfe727624b528c to your computer and use it in GitHub Desktop.
using if statements
Greetings:
behavioral specifications:
- cases are mutually exclusive
if it's morning, say good morning
from 0001 to 1200
if it's afternoon, say good afternoon
from 1201 to 1800
if it's evening, say good evening
from 1801 to 0000
code specifications:
args: 1
number: the time of day
return: String
the appropriate greeting
behavior:
depending on the time, a different greeting is returned
strategy:
answer one correctly at at time
https://www.w3schools.com/js/js_if_else.asp
function greetings(time) {
var response = "";
if ((1 <= time) && (time <= 1200)) {
response = "good morning";
}
if ((1201 <= time) && (time <= 1800)) {
response = "good afternoon";
}
if ((1801 <= time) && (time < 2400)) {
response = "good evening";
}
return response;
}
greetings(1850)
greetings(50)
function greetings(time) {
var response = "";
if ((1 <= time) && (time <= 1200)) {
response = "good morning";
} else if ((1201 <= time) && (time <= 1800)) {
response = "good afternoon";
} else {
response = "good evening"
}
return response;
}
greetings(1850)
greetings(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment