created checkpoint: profile-lookup

made final changes

added release date to Jan 8

made 'prop' argument clearer
pull/5913/head
Akira Laine 2016-01-06 17:47:59 +11:00
parent d40e7c902b
commit 2f72516973
1 changed files with 70 additions and 0 deletions

View File

@ -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 <code>lookUp</code> function that takes <code>firstName</code> and a property (<code>prop</code>) as arguments has been pre-written for you.",
"The function should check if <code>firstName</code> is an actual contact's <code>firstName</code> and the given property (<code>prop</code>) is a property of that contact.",
"If both are true, then return the \"value\" of that property.",
"If <code>firstName</code> does not correspond to any contacts then return <code>\"No such contact\"</code>",
"If <code>prop</code> does not correspond to any valid properties then return <code>\"No such property\"</code>",
""
],
"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: <code>\"Kristian\", \"lastName\"</code> should return <code>\"Vos\"</code>');",
"assert.deepEqual(lookUp(\"Sherlock\", \"likes\"), [\"Intruiging Cases\", \"Violin\"], 'message: <code>\"Sherlock\", \"likes\"</code> should return <code>[\"Intruiging Cases\", \"Violin\"]</code>');",
"assert(typeof lookUp(\"Harry\", \"likes\") === \"object\", 'message: <code>\"Harry\",\"likes\"</code> should return an array');",
"assert(lookUp(\"Bob\", \"number\") === \"No such contact\", 'message: <code>\"Bob\", \"number\"</code> should return \"No such contact\"');",
"assert(lookUp(\"Akira\", \"address\") === \"No such property\", 'message: <code>\"Akira\", \"address\"</code> should return \"No such property\"');"
],
"type": "checkpoint",
"challengeType": 1,
"nameCn": "",
"nameFr": "",
"nameRu": "",
"nameEs": "",
"namePt": ""
},
{
"id": "cf1111c1c11feddfaeb9bdef",
"title": "Generate Random Fractions with JavaScript",