From 7e5305de694dceda5ae739242e186da58a06f55e Mon Sep 17 00:00:00 2001 From: Abhisek Pattnaik Date: Sun, 27 Dec 2015 02:28:55 +0530 Subject: [PATCH] Replacing If/Else chains with Switch --- .../basic-javascript.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 e11da307ca..a6d4405b1c 100644 --- a/seed/challenges/01-front-end-development-certification/basic-javascript.json +++ b/seed/challenges/01-front-end-development-certification/basic-javascript.json @@ -3252,9 +3252,9 @@ "title": "Replacing If/Else chains with Switch", "description": [ "If you have many options to choose from, a switch statement can be easier to write than many chained if/if else statements. The following:", - "
if(val === 1) {
answer = \"a\";
} else if(val === 2) {
answer = \"b\";
} else {
answer = \"c\";
}
", + "
if(val === 1) {
answer = \"a\";
} else if(val === 2) {
answer = \"b\";
} else {
answer = \"c\";
}
", "can be replaced with:", - "
switch (val) {
case 1:
answer = \"a\";
break;
case 2:
answer = \"b\";
break;
default:
answer = \"c\";
}
", + "
switch (val) {
case 1:
answer = \"a\";
break;
case 2:
answer = \"b\";
break;
default:
answer = \"c\";
}
", "

Instructions

", "Change the chained if/if else statements into a switch statement." ], @@ -3267,7 +3267,9 @@ "assert(myTest(42) === \"The Answer\", 'message: myTest(42) should be \"The Answer\"');", "assert(myTest(1) === \"There is no #1\", 'message: myTest(1) should be \"There is no #1\"');", "assert(myTest(99) === \"Missed me by this much!\", 'message: myTest(99) should be \"Missed me by this much!\"');", - "assert(myTest(7) === \"Ate Nine\", 'message: myTest(7) should be \"Ate Nine\"');" + "assert(myTest(7) === \"Ate Nine\", 'message: myTest(7) should be \"Ate Nine\"');", + "assert(myTest(\"John\") === \"\", 'message: myTest(\"John\") should be \"\" (empty string)');", + "assert(myTest(156) === \"\", 'message: myTest(156) should be \"\" (empty string)');" ], "challengeSeed": [ "function myTest(val) {", @@ -3285,7 +3287,7 @@ " } else if(val === 7) {", " answer = \"Ate Nine\";", " }", - "", + " ", " // Only change code above this line ", " return answer; ", "}",