๐Ÿ”ฎ Day 1 - Spell Solutions#

Oda the Data Otterโ€™s Magic Answer Key! ๐Ÿฆฆโœจ


โœจ Spell 1: Simple If-Else Magic - Solutions#

Activity Questions & Answers:#

1. Change my_favorite_number to different values (try 3, 10, 1)

  • my_favorite_number <- 3: Output โ†’ โ€œ๐Ÿ’ญ Thatโ€™s a nice small number!โ€ (because 3 is not > 5)

  • my_favorite_number <- 10: Output โ†’ โ€œ๐ŸŽ‰ Wow! Thatโ€™s a big number!โ€ (because 10 > 5)

  • my_favorite_number <- 1: Output โ†’ โ€œ๐Ÿ’ญ Thatโ€™s a nice small number!โ€ (because 1 is not > 5)

2. Can you predict the message before running it?

  • If the number is greater than 5 โ†’ โ€œbig numberโ€ message

  • If the number is 5 or less โ†’ โ€œsmall numberโ€ message


โœจ Spell 2: Multiple Choices - Solutions#

Activity Questions & Answers:#

1. Change favorite_color to your actual favorite color

  • If your color is โ€œredโ€, โ€œblueโ€, or โ€œgreenโ€ โ†’ specific mood message

  • Any other color โ†’ โ€œโœจ You have a unique and magical taste!โ€

2. If your color isnโ€™t there, what message do you get?

  • You get the default message: โ€œโœจ You have a unique and magical taste!โ€

3. Extension: Add your favorite color with a special message

# set the locale to English and UTF-8 encoding so that emojis can be displayed correctly
Sys.setlocale("LC_CTYPE", "en_US.UTF-8")
'en_US.UTF-8'
# ๐ŸŒˆ Oda's color mood detector with added purple option
favorite_color <- "purple"

if (favorite_color == "red") {
  print("๐Ÿ”ฅ You like bold and exciting adventures!")
} else if (favorite_color == "blue") {
  print("๐ŸŒŠ You love calm and peaceful vibes!")
} else if (favorite_color == "green") {
  print("๐ŸŒฑ You enjoy nature and growing things!")
} else if (favorite_color == "purple") { # NEW line added to include a new color purple
  print("๐Ÿ’œ You love magic and mystery!") # NEW line added
} else {
  print("โœจ You have a unique and magical taste!")
}
[1] "๐Ÿ’œ You love magic and mystery!"

โœจ Spell 3: Number Range Detective - Solutions#

Activity Questions & Answers:#

1. Predict which otter for each number:

  • mystery_number <- 5: โ€œ๐Ÿฃ Tiny number - like a baby otter!โ€ (5 < 10)

  • mystery_number <- 25: โ€œ๐Ÿฆฆ Medium number - like a young otter!โ€ (25 < 50)

  • mystery_number <- 75: โ€œ๐Ÿ”๏ธ Big number - like a mountain otter!โ€ (75 < 100)

  • mystery_number <- 150: โ€œ๐Ÿš€ Huge number - like a space otter!โ€ (150 >= 100)

2. What happens with 0 or negative numbers?

  • mystery_number <- 0: โ€œ๐Ÿฃ Tiny number - like a baby otter!โ€ (0 < 10)

  • mystery_number <- -5: โ€œ๐Ÿฃ Tiny number - like a baby otter!โ€ (-5 < 10)

3. Why check smaller numbers first?

  • R checks conditions from top to bottom and stops at the first TRUE condition

  • If we checked larger ranges first, smaller numbers might never reach their specific conditions


โœจ Spell 4: AND Condition Magic - Solutions#

Activity Questions & Answers:#

1. Test weather combinations:

  • temperature <- 15, weather <- "sunny": โ€œ๐Ÿ  Maybe itโ€™s a good day to stay insideโ€ฆโ€ (15 is not > 20)

  • temperature <- 25, weather <- "rainy": โ€œ๐Ÿ  Maybe itโ€™s a good day to stay insideโ€ฆโ€ (weather is not โ€œsunnyโ€)

  • temperature <- 30, weather <- "sunny": โ€œ๐Ÿ–๏ธ Perfect day for swimming and playing!โ€ (both conditions true)

2. Challenge Questions:

  • Only temperature good but weather bad: No perfect day (need BOTH conditions)

  • Only weather good but temperature bad: No perfect day (need BOTH conditions)

  • Why need BOTH true: AND (&) requires ALL conditions to be true

3. ๐ŸŽฏ Experiment: Try creating your own perfect day conditions: Example output:

temperature <- 25
weather <- "sunny"
wind_speed <- 60

if ((temperature > 20) & (weather == "sunny") & (wind_speed < 10)) {
  print("๐Ÿ–๏ธ Perfect day for swimming and playing!")
  print("๐Ÿฆฆ Oda is super happy!")
} else if (wind_speed > 50){
  print("๐Ÿ’จ Wow I'm being blown away, hide in the bunk!")
}else {
  print("๐Ÿ  Maybe it's a good day to stay inside and code!")
}
[1] "๐Ÿ’จ Wow I'm being blown away, hide in the bunk!"
  • (Because wind_speed = 60, which is > 50, so the first condition fails and the second condition is true)


โœจ Spell 5: OR Condition Magic - Solutions#

Activity Questions & Answers:#

1. Test different snacks:

  • snack <- "apple": โ€œ๐Ÿฅฐ Yummy! Oda loves healthy snacks!โ€ (apple is in healthy list)

  • snack <- "banana": โ€œ๐Ÿฅฐ Yummy! Oda loves healthy snacks!โ€ (banana is in healthy list)

  • snack <- "cookie": โ€œ๐Ÿช Sweet treat! But just a little bit!โ€ (cookie is in sweet list)

  • snack <- "pizza": โ€œ๐Ÿค” Hmm, Oda isnโ€™t sure about this snackโ€ฆโ€ (not in any list)

2. What happens with โ€œAppleโ€ vs โ€œappleโ€?

  • snack <- "Apple": โ€œ๐Ÿค” Hmm, Oda isnโ€™t sureโ€ฆโ€ (R is case-sensitive - โ€œAppleโ€ โ‰  โ€œappleโ€)

3. Extension: Add more snacks

# ๐ŸŽ Oda's snack time detector with added protein category
snack <- "cheese"

if (snack == "apple" | snack == "banana" | snack == "carrot") {
  print("๐Ÿฅฐ Yummy! Oda loves healthy snacks!")
  print("๐Ÿ’ช This will give me energy for coding!")
} else if (snack == "cookie" | snack == "candy") {
  print("๐Ÿช Sweet treat! But just a little bit!")
} else if (snack == "cheese" | snack == "nuts") {
  print("๐Ÿง€ Protein power! Great for brain fuel!")
} else {
  print("๐Ÿค” Hmm, Oda isn't sure about this snack...")
}
[1] "๐Ÿง€ Protein power! Great for brain fuel!"

โœจ Spell 6: Age Group Sorter - Solutions#

Activity Questions & Answers:#

1. Test different ages:

  • age <- 5: โ€œ๐Ÿฃ Little explorer - just starting the adventure!โ€ (5 < 6)

  • age <- 8: โ€œ๐Ÿงธ Young adventurer - ready for fun!โ€ (6 โ‰ค 8 โ‰ค 9)

  • age <- 12: โ€œ๐Ÿง™โ€โ™€๏ธ Data wizard in training - thatโ€™s you!โ€ (10 โ‰ค 12 โ‰ค 14)

  • age <- 16: โ€œ๐Ÿš€ Teen tech master - almost ready to rule the world!โ€ (15 โ‰ค 16 โ‰ค 18)

  • age <- 25: โ€œ๐ŸŽ“ Wise adult - teaching the next generation!โ€ (25 > 18)

2. Edge cases:

  • age <- 6: โ€œ๐Ÿงธ Young adventurerโ€ (6 โ‰ฅ 6 is true)

  • age <- 14: โ€œ๐Ÿง™โ€โ™€๏ธ Data wizard in trainingโ€ (14 โ‰ค 14 is true)

3. Why use >= and <=?

  • To include the boundary ages (like exactly 6 or exactly 14)

  • Makes sure no ages โ€œfall through the cracksโ€

4. ๐ŸŽฏ Challenge Solution: Age-Based Activity Sorter

# ๐ŸŽฏ Oda's Age-Based Activity Sorter - Perfect activities for each age group!
age <- 12  # Try different ages: 4, 7, 13, 16, 25

if (age < 6) {
  print("๐Ÿฃ Little Explorer Activities:")
  print("๐Ÿงธ Play with building blocks and stuffed animals")
  print("๐Ÿ“š Listen to picture book stories") 
  print("๐ŸŽจ Finger painting and simple crafts")
  print("๐ŸŽต Sing-along songs and nursery rhymes")
} else if (age >= 6 & age <= 9) {
  print("๐Ÿงธ Young Adventurer Activities:")
  print("๐ŸŽฎ Simple board games and puzzles")
  print("โšฝ Team sports like soccer or basketball")
  print("๐Ÿ”ฌ Basic science experiments")
  print("๐ŸŽญ Drama and pretend play")
} else if (age >= 10 & age <= 14) {
  print("๐Ÿง™โ€โ™€๏ธ Data Wizard Activities:")
  print("๐Ÿ’ป Learn coding and computer programming!")
  print("๐ŸŽธ Learn musical instruments")
  print("๐Ÿ“ฑ Create digital art and videos")
  print("๐Ÿงฉ Complex strategy games and escape rooms")
} else if (age >= 15 & age <= 18) {
  print("๐Ÿš€ Teen Tech Master Activities:")
  print("๐Ÿš— Learn to drive and gain independence")
  print("๐Ÿ’ผ Part-time jobs and internships")
  print("๐ŸŽ“ Prepare for college and career planning")
  print("๐ŸŒ Volunteer work and community service")
} else {
  print("๐ŸŽ“ Wise Adult Activities:")
  print("๐Ÿ‘จโ€๐Ÿซ Teach and mentor the next generation")
  print("๐Ÿ’ฐ Career advancement and financial planning")
  print("๐ŸŒฟ Hobbies like gardening, cooking, or travel")
}

print(paste("๐ŸŽ‚ Perfect activities for someone who is", age, "years old!"))
[1] "๐Ÿง™โ€โ™€๏ธ Data Wizard Activities:"
[1] "๐Ÿ’ป Learn coding and computer programming!"
[1] "๐ŸŽธ Learn musical instruments"
[1] "๐Ÿ“ฑ Create digital art and videos"
[1] "๐Ÿงฉ Complex strategy games and escape rooms"
[1] "๐ŸŽ‚ Perfect activities for someone who is 12 years old!"

โœจ Spell 7: Multiple Actions Spell - Solutions#

Activity Questions & Answers:#

1. Test magic words:

  • magic_word <- "abracadabra": Full classic magic show (4 actions)

  • magic_word <- "alakazam": Fireworks show (3 actions)

  • magic_word <- "hocus pocus": Unknown magic word message (2 actions)

2. Why multiple print() statements?

  • Each print() creates a separate line of output

  • Creates a sequence of actions that tell a story

  • Makes the magic show feel more dramatic and realistic

3. Creative Challenge: Add third magic word

# ๐ŸŽช Oda's magic show with multiple tricks including new "presto" magic
magic_word <- "presto"

if (magic_word == "abracadabra") {
  print("โœจ *Sparkles appear in the air*")
  print("๐ŸŽฉ *A rabbit pops out of the hat*")
  print("๐ŸŒŸ *The crowd cheers loudly*")
  print("๐Ÿฆฆ Oda takes a bow!")
} else if (magic_word == "alakazam") {
  print("๐Ÿ’ฅ *Thunder sound effect*")
  print("๐ŸŽ† *Colorful fireworks explode*")
  print("๐Ÿฆฆ Oda does a backflip!")
} else if (magic_word == "presto") {
  print("๐Ÿฐ *Magic rabbits hop everywhere*")
  print("๐ŸŒˆ *Rainbow appears in the sky*")
  print("๐Ÿฆฆ Oda waves her magic wand!")
} else {
  print("๐Ÿ˜… Oops! That's not a magic word Oda knows...")
  print("๐Ÿ’ก Try 'abracadabra', 'alakazam', or 'presto'!")
}
[1] "๐Ÿฐ *Magic rabbits hop everywhere*"
[1] "๐ŸŒˆ *Rainbow appears in the sky*"
[1] "๐Ÿฆฆ Oda waves her magic wand!"

โœจ Spell 8: No Else Challenge - Solutions#

Activity Questions & Answers:#

1. Test point values:

  • points <- 30: Only โ€œ๐ŸŽฏ You have 30 points total!โ€ (no achievements met)

  • points <- 60: โ€œ๐Ÿ‘ GOOD JOB! Keep practicing!โ€ + total points (โ‰ฅ50 condition met)

  • points <- 80: โ€œโญ AWESOME! Youโ€™re doing great!โ€ + โ€œ๐Ÿ‘ GOOD JOB! Keep practicing!โ€ + total points (โ‰ฅ75 and โ‰ฅ50 met)

  • points <- 120: All three achievements + total points (โ‰ฅ100, โ‰ฅ75, โ‰ฅ50 all met)

2. Why multiple achievement messages?

  • Each if statement runs independently (no else to stop them)

  • High scores qualify for multiple achievement levels simultaneously

  • Like earning multiple badges in a game

3. Minimum points for all achievements?

  • Need at least 100 points to trigger all three achievement conditions


โœจ Spell 9: Code Order Magic - Solutions#

Activity Questions & Answers:#

1. Compare both versions:

Version 9A (Correct):

  • position <- 1: โ€œ๐Ÿฅ‡ GOLD MEDAL!โ€

  • position <- 2: โ€œ๐Ÿฅˆ SILVER MEDAL!โ€

  • position <- 3: โ€œ๐Ÿฅ‰ BRONZE MEDAL!โ€

Version 9B (Wrong):

  • position <- 1: โ€œ๐Ÿ‘ Good race! Keep practicing!โ€ (WRONG!)

  • position <- 2: โ€œ๐Ÿ‘ Good race! Keep practicing!โ€ (WRONG!)

  • position <- 3: โ€œ๐Ÿ‘ Good race! Keep practicing!โ€ (WRONG!)

2. Why Version 9B always says โ€œGood race!โ€

  • First condition position >= 1 is TRUE for positions 1, 2, and 3

  • R stops at the first TRUE condition and never checks the others

3. Which conditions never run in Version 2?

  • The position == 1 and position == 2 conditions never run

  • Because position >= 1 catches everything first

Key Lesson: Always check SPECIFIC conditions before GENERAL ones!


โœจ Spell 10: String Detective - Solutions#

Activity Questions & Answers:#

1. Test different names:

  • name <- "Jo": โ€œ๐Ÿ“ You have a nice short name!โ€ (2 letters โ‰ค 4)

  • name <- "Elizabeth": โ€œ๐Ÿ“š Wow! You have a beautifully long name!โ€ (9 letters โ‰ฅ 8)

  • name <- "Sam": โ€œ๐Ÿ“ You have a nice short name!โ€ (3 letters โ‰ค 4)

  • name <- "Christopher": โ€œ๐Ÿ“š Wow! You have a beautifully long name!โ€ (11 letters โ‰ฅ 8)

2. What does nchar() do?

  • nchar() counts the number of characters (letters) in a text string

  • nchar("hello") returns 5

  • nchar("R") returns 1

3. Why canโ€™t Oda find Mike? THE BIG PROBLEM!

  • When name <- "Mike":

    1. First condition: nchar("Mike") <= 4 โ†’ 4 <= 4 โ†’ TRUE!

    2. R prints โ€œ๐Ÿ“ You have a nice short name!โ€ and stops

    3. The Mike-finding condition never gets checked!

4. How to fix it:

# ๐Ÿ” FIXED version - Oda can now find Mike! Check for Mike FIRST:
name <- "Mike"

if (name == "mike" | name == "Mike" | name == "Michael" | name == "michael"){
  print("๐Ÿ‘ฅ Hi Mike, long time no see! I've caught some clams today! ๐ŸŒŠ ๐Ÿš ๐Ÿฆช")
} else if (nchar(name) <= 4){
  print("๐Ÿ“ You have a nice short name!")
} else if (nchar(name) >= 8) {
  print("๐Ÿ“š Wow! You have a beautifully long name!")
} else {
  print("โœจ You have a perfectly medium-sized name!")
}

# Bonus: Count the letters in your name!
print(paste("๐Ÿ”ข Your name has", nchar(name), "letters!"))
[1] "๐Ÿ‘ฅ Hi Mike, long time no see! I've caught some clams today! ๐ŸŒŠ ๐Ÿš ๐Ÿฆช"
[1] "๐Ÿ”ข Your name has 4 letters!"

(Now Oda can find Mike because we check for his name BEFORE checking the length!)


โœจ Spell 11: Temperature Zone Detective - Solutions#

Activity Questions & Answers:#

1. Test temperatures:

  • temperature <- -5: โ€œ๐ŸงŠ FREEZING!โ€ + winter coat message (-5 โ‰ค 0)

  • temperature <- 5: โ€œ๐Ÿฅถ COLD! Perfect sweater weather!โ€ (1 โ‰ค 5 โ‰ค 10)

  • temperature <- 15: โ€œ๐Ÿ˜Š COOL! Great for a light jacket!โ€ (11 โ‰ค 15 โ‰ค 20)

  • temperature <- 25: โ€œโ˜€๏ธ WARM! Perfect for playing outside!โ€ (21 โ‰ค 25 โ‰ค 30)

  • temperature <- 35: โ€œ๐Ÿ”ฅ HOT!โ€ + swimming message (35 โ‰ฅ 31)

2. Why use >= and <= instead of > and <?

  • To include exact boundary temperatures (like exactly 0ยฐ, 21ยฐ, etc.)

  • Prevents temperatures from โ€œfalling betweenโ€ categories

  • temperature <- 20 with < 20 would not be caught by the โ€œcoolโ€ category

3. Edge cases:

  • temperature <- 0: โ€œ๐ŸงŠ FREEZING!โ€ (0 โ‰ค 0 is true)

  • temperature <- 21: โ€œโ˜€๏ธ WARM!โ€ (21 โ‰ฅ 21 is true)

  • temperature <- 20.5: โ€œ๐Ÿค” Something seems fishy with this temperatureโ€ฆโ€


โœจ Spell 12: Magical Creatures - Solutions#

Activity Questions & Answers:#

1. Test different combinations:

  • creature_size <- 15, creature_color <- "purple": โ€œ๐Ÿงšโ€โ™€๏ธ You found a tiny fairy!โ€

  • creature_size <- 50, creature_color <- "gold": โ€œ๐Ÿ‰ You found a baby dragon!โ€

  • creature_size <- 50, creature_color <- "blue": โ€œ๐Ÿฆฆ You found Oda the Otter!โ€

  • creature_size <- 150, creature_color <- "any": โ€œ๐Ÿ‘น You found a friendly giant!โ€

2. What happens with negative/zero size?

  • creature_size <- 0: โ€œ๐Ÿ› You found a magical bug!โ€ (0 โ‰ค 20, not purple)

  • creature_size <- -5: โ€œ๐Ÿ› You found a magical bug!โ€ (-5 โ‰ค 20, not purple)

3. How nested conditions work:

  • Outer condition checks size range first

  • Inner conditions check color within that size range

  • Like a decision tree: size โ†’ then color โ†’ then result

4. Extension ideas:

# ๐Ÿฆ„ EXTENDED Magical Creature Classifier with more sizes and colors
creature_size <- 150   # Size in cm
creature_color <- "silver" # Try different colors

if (creature_size <= 20) {
  if (creature_color == "purple") {
    print("๐Ÿงšโ€โ™€๏ธ You found a tiny fairy!")
  } else if (creature_color == "invisible") {
    print("๐Ÿ‘ป You found an invisible sprite!")
  } else {
    print("๐Ÿ› You found a magical bug!")
  }
} else if (creature_size >= 21 & creature_size <= 100) {
  if (creature_color == "purple") {
    print("๐Ÿฆ„ You found a unicorn!")
  } else if (creature_color == "gold") {
    print("๐Ÿ‰ You found a baby dragon!")
  } else if (creature_color == "rainbow") {
    print("๐Ÿฆ„ You found a rainbow unicorn!")
  } else {
    print("๐Ÿฆฆ You found Oda the Otter!")
  }
} else if (creature_size >= 101 & creature_size <= 200) {
  if (creature_color == "silver") {
    print("๐Ÿบ You found a silver wolf!")
  } else if (creature_color == "gold") {
    print("๐Ÿ‰ You found a teenage dragon!")
  } else {
    print("๐Ÿป You found a friendly bear!")
  }
} else if (creature_size >= 201) {
  print("๐Ÿ‘น You found a friendly giant!")
}

print(paste("๐Ÿ“ Your creature is", creature_size, "cm tall and", creature_color, "colored!"))
[1] "๐Ÿบ You found a silver wolf!"
[1] "๐Ÿ“ Your creature is 150 cm tall and silver colored!"

(Because creature_size = 150 falls in the 101-200 range, and creature_color = โ€œsilverโ€ matches the wolf condition)

5. SUPER CHALLENGE: Flying Ability Extension

# ๐Ÿš€ ULTIMATE Magical Creature Classifier with Flying Abilities!
creature_size <- 50      # Size in cm
creature_color <- "gold" # Try different colors  
creature_ability <- "flying"  # Try: "flying", "swimming", "invisible"

if (creature_size <= 20) {
  if (creature_color == "purple") {
    if (creature_ability == "flying") {
      print("๐Ÿงšโ€โ™€๏ธโœˆ๏ธ You found a flying tiny fairy!")
      print("๐Ÿ’ซ She can sprinkle magic dust from the sky!")
    } else if (creature_ability == "invisible") {
      print("๐Ÿงšโ€โ™€๏ธ๐Ÿ‘ป You found an invisible tiny fairy!")
      print("๐Ÿ” You can only see sparkles where she flies!")
    } else {
      print("๐Ÿงšโ€โ™€๏ธ You found a tiny fairy!")
    }
  } else {
    print("๐Ÿ› You found a magical bug!")
  }
} else if (creature_size >= 21 & creature_size <= 100) {
  if (creature_color == "gold") {
    if (creature_ability == "flying") {
      print("๐Ÿ‰โœˆ๏ธ You found a flying baby dragon!")
      print("๐Ÿ”ฅ It breathes fire while soaring through the clouds!")
    } else if (creature_ability == "swimming") {
      print("๐Ÿ‰๐ŸŒŠ You found a swimming baby dragon!")
      print("๐Ÿ’ง It can breathe underwater and shoots water blasts!")
    } else {
      print("๐Ÿ‰ You found a baby dragon!")
    }
  } else if (creature_color == "purple") {
    if (creature_ability == "flying") {
      print("๐Ÿฆ„โœˆ๏ธ You found a flying unicorn!")
      print("๐ŸŒˆ It leaves rainbow trails in the sky!")
    } else {
      print("๐Ÿฆ„ You found a unicorn!")
    }
  } else {
    print("๐Ÿฆฆ You found Oda the Otter!")
  }
} else if (creature_size >= 101) {
  if (creature_ability == "flying") {
    print("๐Ÿ‘นโœˆ๏ธ You found a flying friendly giant!")
    print("โ˜๏ธ The ground shakes when it lands!")
  } else {
    print("๐Ÿ‘น You found a friendly giant!")
  }
}

print(paste("๐Ÿ“ Your creature is", creature_size, "cm tall,", creature_color, "colored, and has", creature_ability, "ability!"))
[1] "๐Ÿ‰โœˆ๏ธ You found a flying baby dragon!"
[1] "๐Ÿ”ฅ It breathes fire while soaring through the clouds!"
[1] "๐Ÿ“ Your creature is 50 cm tall, gold colored, and has flying ability!"

(Because creature_size = 50, creature_color = โ€œgoldโ€, and creature_ability = โ€œflyingโ€ all match the flying baby dragon conditions)


๐ŸŽ‰ Congratulations! Youโ€™ve mastered all 12 magical spells! Youโ€™re now ready to cast decision-making magic in any R adventure! ๐Ÿฆฆโœจ