Group Group Group Group Group Group Group Group Group

Chapter 2 mini exercise help

Hello,

I am having problems with the 3 part of the question in the mini exercise.

  1. Declare a constant tuple that contains three Int values followed by a Double. Use this to represent a date (month, day, year) followed by an average temperature for that date.
  2. Change the tuple to name the constituent components. Give them names related to the data that they contain: month, day, year and averageTemperature.
  3. In one line, read the day and average temperature values into two constants. You’ll need to employ the underscore to ignore the month and year.

so far I have let avgTemperature:(day: Int, month: Int, year: Int, averageTemperature: Double) = (9, 5, 1982, 77.6)
What is meant by reading the day and average temperature values into two constants?

Here is my code:

 // #1 - Declare a type alias for the myDate tuple    
typealias myDate = (Int, Int, Int, Double)

// #2 - Declare a constant tuple birthdate with my data giving them their names
let birthdate: myDate = (day: 12, month: 6, year: 1962, averageTemperature: 12.34)
print(birthdate)

// #3 Read the day and average temp and ignore the others using '_'
let (day, _ , _ , averageTemperature) = birthdate
print(day, averageTemperature) 

Hope this helps.

Downloading the book, also contains the solutions for the challenges.

  1. Declare a constant that contains three int values followed by a Double.
    let temperature = (10, 17, 2015, 15.7)
  2. Change the tuple to name the components:
    let temperature = (month: 10, day: 17, year: 2015, averageTemperature: 15.7)
  3. In one line, read the day and average temperature values into two constants
    let ( _ , day, _ , averageTemperature) = temperature

“What is meant by reading the day and average temperature values into two constants?”

In the line above you have two constants: day and averageTemperature. The values with underscore are ignored (in this case month and years).

This is equivalent to:
let day = temperature.day
let averageTemperature = temperature.averageTemperature

Welcome to the community @shaogden! Looks like there are a few helpful answers here. Are you still facing any issues with the mini exercise?

Best,
Gina