From 3fe22ada0f0d4b6cf169c53b48be2cc4b75d7a81 Mon Sep 17 00:00:00 2001 From: Akira Laine Date: Wed, 6 Jan 2016 17:47:59 +1100 Subject: [PATCH] created checkpoint: profile-lookup made final changes added release date to Jan 8 made 'prop' argument clearer --- .../basic-javascript.json | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/challenges/01-front-end-development-certification/basic-javascript.json b/challenges/01-front-end-development-certification/basic-javascript.json index a6da82be6f0..ac423af4614 100644 --- a/challenges/01-front-end-development-certification/basic-javascript.json +++ b/challenges/01-front-end-development-certification/basic-javascript.json @@ -3923,6 +3923,76 @@ "type": "waypoint", "challengeType": 1 }, + { + "id": "5688e62ea601b2482ff8422b", + "title": "Profile Lookup", + "description": [ + "We have an array of objects representing different people in our contacts lists.", + "A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.", + "The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.", + "If both are true, then return the \"value\" of that property.", + "If firstName does not correspond to any contacts then return \"No such contact\"", + "If prop does not correspond to any valid properties then return \"No such property\"", + "" + ], + "releasedOn": "January 8, 2016", + "challengeSeed": [ + "//Setup", + "var contacts = [", + " {", + " \"firstName\": \"Akira\",", + " \"lastName\": \"Laine\",", + " \"number\": \"0543236543\",", + " \"likes\": [\"Pizza\", \"Coding\", \"Brownie Points\"]", + " },", + " {", + " \"firstName\": \"Harry\",", + " \"lastName\": \"Potter\",", + " \"number\": \"0994372684\",", + " \"likes\": [\"Hogwarts\", \"Magic\", \"Hagrid\"]", + " },", + " {", + " \"firstName\": \"Sherlock\",", + " \"lastName\": \"Holmes\",", + " \"number\": \"0487345643\",", + " \"likes\": [\"Intruiging Cases\", \"Violin\"]", + " },", + " {", + " \"firstName\": \"Kristian\",", + " \"lastName\": \"Vos\",", + " \"number\": \"unknown\",", + " \"likes\": [\"Javascript\", \"Gaming\", \"Foxes\"]", + " },", + "];", + "", + "", + "function lookUp(firstName, prop){", + "// Only change code below this line", + "", + "// Only change code above this line", + "}", + "", + "// Change these values to test your function", + "lookUp(\"Akira\", \"likes\");" + ], + "solutions": [ + "var contacts = [\n {\n \"firstName\": \"Akira\",\n \"lastName\": \"Laine\",\n \"number\": \"0543236543\",\n \"likes\": [\"Pizza\", \"Coding\", \"Brownie Points\"]\n },\n {\n \"firstName\": \"Harry\",\n \"lastName\": \"Potter\",\n \"number\": \"0994372684\",\n \"likes\": [\"Hogwarts\", \"Magic\", \"Hagrid\"]\n },\n {\n \"firstName\": \"Sherlock\",\n \"lastName\": \"Holmes\",\n \"number\": \"0487345643\",\n \"likes\": [\"Intruiging Cases\", \"Violin\"]\n },\n {\n \"firstName\": \"Kristian\",\n \"lastName\": \"Vos\",\n \"number\": \"unknown\",\n \"likes\": [\"Javascript\", \"Gaming\", \"Foxes\"]\n },\n];\n\n\n//Write your function in between these comments\nfunction lookUp(name, prop){\n for(var i in contacts){\n if(contacts[i].firstName === name) {\n return contacts[i][prop] || \"No such property\";\n }\n }\n return \"No such contact\";\n}\n//Write your function in between these comments\n\nlookUp(\"Akira\", \"likes\");" + ], + "tests": [ + "assert(lookUp('Kristian','lastName') === \"Vos\", 'message: \"Kristian\", \"lastName\" should return \"Vos\"');", + "assert.deepEqual(lookUp(\"Sherlock\", \"likes\"), [\"Intruiging Cases\", \"Violin\"], 'message: \"Sherlock\", \"likes\" should return [\"Intruiging Cases\", \"Violin\"]');", + "assert(typeof lookUp(\"Harry\", \"likes\") === \"object\", 'message: \"Harry\",\"likes\" should return an array');", + "assert(lookUp(\"Bob\", \"number\") === \"No such contact\", 'message: \"Bob\", \"number\" should return \"No such contact\"');", + "assert(lookUp(\"Akira\", \"address\") === \"No such property\", 'message: \"Akira\", \"address\" should return \"No such property\"');" + ], + "type": "checkpoint", + "challengeType": 1, + "nameCn": "", + "nameFr": "", + "nameRu": "", + "nameEs": "", + "namePt": "" + }, { "id": "cf1111c1c11feddfaeb9bdef", "title": "Generate Random Fractions with JavaScript",