Bird
0
0

How would you fix this Swift code to run correctly?

hard📝 Application Q9 of 15
Swift - Variables and Constants
How would you fix this Swift code to run correctly?
let a = 3 let b = 4; print(a + b)
AAdd parentheses around print argument
BRemove all semicolons
CChange 'let' to 'var'
DAdd a semicolon between 'let a = 3' and 'let b = 4;'
Step-by-Step Solution
Solution:
  1. Step 1: Identify statement separation issue

    Two variable declarations are on the same line without a semicolon separating them.
  2. Step 2: Fix by adding semicolon

    Adding a semicolon between the two declarations separates them correctly.
  3. Final Answer:

    Add a semicolon between 'let a = 3' and 'let b = 4;' -> Option D
  4. Quick Check:

    Fix missing semicolon = C [OK]
Quick Trick: Separate multiple declarations on one line with semicolons [OK]
Common Mistakes:
  • Removing semicolons without fixing statement separation
  • Changing variable declaration keywords unnecessarily
  • Misunderstanding print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes