JavaScript bootcamp · Lab 35

Object lookup

easyObjects10 minLesson: Objects

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Build {alice: 90, bob: 85, cara: 92}. Read a name and log the score, or missing.

Input. One name.

Output. Score or missing.

Examples

Example 1
Input
bob
Output
85
Example 2
Input
dave
Output
missing
Hint
  1. scores[name] ?? 'missing'
Show correct code

Peek only after you have tried. You can still Check your own version.

const scores = { alice: 90, bob: 85, cara: 92 };
const name = readLine().trim();
console.log(scores[name] ?? 'missing');
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.