Find the compile error
Apex basics · Beginner · 10 min · Runs in your Salesforce Developer org · Free
The starter method does not compile. Fix three errors so `total(price, qty)` returns a formatted line-item total such as `Total: 30`. A semicolon is missing, the return type is wrong and double quotes have snuck in. Keep the method name and parameters.
The challenge
Fix every compile error in total(Integer price, Integer qty) so it returns a String such as Total: 30.
Examples:
total(10, 3)→Total: 30total(0, 100)→Total: 0total(5, 5)→Total: 25
Requirements:
total(10, 3)should beTotal: 30.total(0, 100)should beTotal: 0.total(5, 5)should beTotal: 25.total(1, 1)should beTotal: 1.total(100, 100)should beTotal: 10000.
Starter code
Integer total(Integer price, Integer qty) {
Integer sum = price * qty
return "Total: " + sum
}
Related drills
You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.
‹ break and continue · Group records in a Map<String, List<Contact>> ›