Created
April 21, 2018 13:44
-
-
Save colevandersWands/425b3125ce3e00ed25dfe727624b528c to your computer and use it in GitHub Desktop.
using if statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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