E-commerce search page: when a shopper searches a product, show the top-rated brand selling it. In v1 there's just one product and one brand.
You start with:
let product = "Laptop"
let brand = "TechPro"
let rating = 4
Build:
Laptop 1. TechPro (4)
Rules:
- The first line is the product name.
- The second line is a ranked entry written as
"1. Brand (rating)". - Keep each line in its own variable (
productLineandbrandLine), join them with a newline"\n"and print the result withprint(...).
Swift puts any value into a string with interpolation:
"\(rating)".
productLine + "\n" + brandLine joins both lines into one string.
let product = "Laptop"
let brand = "TechPro"
let rating = 4
let productLine = product
let brandLine = "1. \(brand) (\(rating))"
print(productLine + "\n" + brandLine)
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
