

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: The Error Interface
incomplete
2: Formatting Strings Review
incomplete
3: The Error Interface
incomplete
4: Errors Quiz
incomplete
5: The Errors Package
incomplete
6: Panic
incomplete
7: User Input
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
A convenient way to format strings in Go is by using the standard library's fmt.Sprintf() function. It's a string interpolation function, similar to Python's f-strings. The %v substring uses the type's default formatting, which is often what you want.
const name = "Kim"
const age = 22
s := fmt.Sprintf("%v is %v years old.", name, age)
// s = "Kim is 22 years old."
The equivalent Python code:
name = "Kim"
age = 22
s = f"{name} is {age} years old."
# s = "Kim is 22 years old."
s := fmt.Sprintf("I am %f years old", 10.523)
// s = I am 10.523000 years old
// The ".2" rounds the number to 2 decimal places
s := fmt.Sprintf("I am %.2f years old", 10.523)
// s = I am 10.52 years old
We need better error logs for our backend developers to help them debug their code.
Complete the getSMSErrorString() function. It should return a string with this format:
SMS that costs $COST to be sent to 'RECIPIENT' cannot be sent
COST is the cost of the SMS, always showing the price formatted to 2 decimal places.RECIPIENT is the stringified representation of the recipient's phone numberBe sure to include the $ symbol, and wrap the recipient in single quotes.