All puzzles
Per page
L
Traversal ยท Filter into a new list

Under $10

When someone clicks the cheapButton button, make a new cheap list with every price in the prices list that is under 10. Show the cheap list in the cheapLabel label.

The label shows 4.5,7.25,9.

11 strips: L1 to L11

onEvent("cheapButton", "click", function() {
L1
appendItem(cheap, i);
L2
});
L3
setText("cheapLabel", cheap);
L4
var cheap = [];
L5
}
L6
if (prices[i] < 10) {
L7
for (var i = 0; i < prices.length; i++) {
L8
appendItem(cheap, prices[i]);
L9
}
L10
var prices = [4.5, 12, 7.25, 30, 9];
L11

Answer key: L. Under $10

Order: L11, L1, L5, L8, L7, L9, L6, L10, L4, L3. Extra: L2

var prices = [4.5, 12, 7.25, 30, 9];
onEvent("cheapButton", "click", function() {
	var cheap = [];
	for (var i = 0; i < prices.length; i++) {
		if (prices[i] < 10) {
			appendItem(cheap, prices[i]);
		}
	}
	setText("cheapLabel", cheap);
});

Extra strip: appendItem(cheap, i);. i is the index, not the price. The label shows 0,2,4.