From ad120dd3cd8f66462a34f7452a5ca8e03d016dad Mon Sep 17 00:00:00 2001 From: patsul12 Date: Fri, 8 Jan 2016 14:28:48 -0800 Subject: [PATCH] added new logical order waypoint --- .../basic-javascript.json | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/seed/challenges/01-front-end-development-certification/basic-javascript.json b/seed/challenges/01-front-end-development-certification/basic-javascript.json index d1ca00ef8fb..c8cd97c9bb4 100644 --- a/seed/challenges/01-front-end-development-certification/basic-javascript.json +++ b/seed/challenges/01-front-end-development-certification/basic-javascript.json @@ -2652,6 +2652,47 @@ "type": "waypoint", "challengeType": 1 }, + { + "id": "5690307fddb111c6084545d7", + "title": "Logical Order in If Else Statements", + "description": [ + "Order is important in if, else if statements.", + "The loop is executed from top to bottom so you will want to be careful of what statement comes first.", + "Take these two functions as an example.", + "Heres the first:", + "
function foo(x) {
if (x < 1) {
return \"Less than one\";
} else if (num < 2) {
return \"Less than two\";
} else {
return \"Greater than or equal to two\";
}
}
", + "And the second just switches the order of the statements:", + "
function bar(x) {
if (x < 2) {
return \"Less than two\";
} else if (num < 1) {
return \"Less than one\";
} else {
return \"Greater than or equal to two\";
}
}
", + "While these two functions look nearly identical if we pass a number to both we get different outputs.", + "
foo(0) // \"Less than one\"
bar(0) // \"Less than two\"
", + "

Instructions

", + "Change the order of logic in the function so that it will return the correct statements in all cases." + ], + "challengeSeed": [ + "function myTest(val) {", + " if(val < 10) {", + " return \"Less than 10\";", + " } else if(val < 5) {", + " return \"Less than 5\";", + " } else {", + " return \"Greater than or equal to 10\";", + " }", + "}", + " ", + "// Change this value to test", + "myTest(7);" + ], + "solutions": [ + "function myTest(val) {\n if(val < 5) {\n return \"Less than 5\"; \n } else if (val < 10) {\n return \"Less than 10\";\n } else {\n return \"Greater than or equal to 10\";\n }\n}" + ], + "tests": [ + "assert(myTest(4) === \"Less than 5\", 'message: myTest(5) should return \"Less than 5\"');", + "assert(myTest(6) === \"Less than 10\", 'message: myTest(6) should return \"Less than 10\"');", + "assert(myTest(11) === \"Greater than or equal to 10\", 'message: myTest(11) should return \"Greater than or equal to 10\"');" + ], + "type": "waypoint", + "challengeType": 1 + }, { "id": "56533eb9ac21ba0edf2244dc", "title": "Chaining If Else Statements",