Whale Talk Step 10 Issue

I’m supposed to get no errors but I get this, still:

WhaleTalk.swift:12:8: error: use of unresolved identifier 'lowerChar'
switch lowerChar {
       ^~~~~~~~~
WhaleTalk.swift:14:14: error: use of unresolved identifier 'lowerChar'
   output += lowerChar.uppercased()
             ^~~~~~~~~
WhaleTalk.swift:20:5: error: 'continue' is only allowed inside a loop
    continue
    ^

This is my current code:

// Create your Whale Talk program below:
var input = "Swift loops? Easy peasy."

var output = ""

for _ in input {
  let char = "GOOD"
  let lowerChar = char.lowercased()
  print(lowerChar)
}

switch lowerChar {
  case "a", "i", "o":
   output += lowerChar.uppercased()
  case "e":
   output += "EE"
  case "u":
   output += "UU"
  default:
    continue
}
1 Like

I’m not familiar with Swift, but as far as I can tell you’re not correctly observing scope for the first two errors:

WhaleTalk.swift:12:8: error: use of unresolved identifier 'lowerChar'
switch lowerChar {
       ^~~~~~~~~
WhaleTalk.swift:14:14: error: use of unresolved identifier 'lowerChar'
   output += lowerChar.uppercased()
             ^~~~~~~~~

because you’re attempting to access a constant lowerChar which is declared inside the for loop from inside the switch statement… Can’t find a concrete explanation of scope in the Swift docs, but have found several articles which suggest it’s block-scoped (i.e. a pair of { } constitutes a scope).

Your third error:

WhaleTalk.swift:20:5: error: 'continue' is only allowed inside a loop
    continue
    ^

is because you’re using the continue keyword inside a switch, when it’s only allowed inside a loop.

3 Likes

Good news, I solved the issue. Now I need to know how to print out e and u in the code.