Color theme
0 day streak0 XPP1
RubyQuiz mode
MISSION 1 OF 3

Find a spice jar

0 XP earned
Ruby track: BeginnerMission: BeginnerHashesSymbol keysLookup defaults
Before you start this beginner track

Variables, arrays, and key-value data. Collection blocks are a step beyond basic syntax.

Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.

x
0 / 6 challenges
KNOWLEDGE CHECK

Predict the result.

What two lines does the spice lookup print?

quest.rb
spices = { cumin: "warm", mint: "cool" }note = spices.fetch(:saffron, "unlisted")puts noteputs spices.length

Each mission is an independent Ruby 3 or later script. Save as quest.rb and run ruby quest.rb. All methods are built into Ruby; no gems or external data are needed.

Review the lesson

A kitchen notebook stores tasting notes in a hash with symbol keys. fetch returns the value for a key, or its supplied fallback when that key is missing. Unlike assigning a missing entry, fetching does not change the notebook. length therefore still reports the original number of stored spices.

Choose your answer+25 XP on first completion