Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
The following program is meant to print the total cost of a purchase, but currently results in an error:
function main() { let cost = 5; let count = 22; printCost(count); } function printCost(num) { let total = itemCost * num; console.log(total); } main();
Which of the below options should be implemented in order to fix the program?
Include itemCost as a parameter on line 8
itemCost
Include cost as an argument on line 5
cost
Change the name of itemCost to be “cost” on line 9 so that it matches the name on line 2
Both options A and B need to be implemented.