Buggy Code Correct Code / Explanation

1

fun piecewisefun(n):
 if (n > 0): n
 else: 0

2

fun cost(topping):
 if string-equal(topping,
"pepperoni"): 10.50
 else string-equal(topping,
"cheese"): 9.00
 else string-equal(topping,
"chicken"): 11.25
 else string-equal(topping,
"broccoli"): 10.25
 else: "That's not on the menu!"
 end
end

3

fun absolute-value(a b):
 if a > b: a - b
 b - a
 end
end

4

fun best-function(f):
 if string-equal(f, “blue”):
 “you win!”
 else if string-equal(f, “blue”):
 “you lose!”
 else if string-equal(f, “red”):
 “Try again!”
 else: “Invalid entry!”
 end
end

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.