All puzzles
Per page
J
Traversal ยท Count

Warm days

When someone clicks the countButton button, count the temperatures in the temps list that are above 70, and show the count in the countLabel label.

The label shows 3 warm days.

11 strips: J1 to J11

}
J1
var temps = [75, 61, 58, 80, 77, 66];
J2
if (temps[i] > 70) {
J3
});
J4
var count = 0;
J5
onEvent("countButton", "click", function() {
J6
count = count + 1;
J7
setText("countLabel", count + " warm days");
J8
for (var i = 0; i < temps.length; i++) {
J9
for (var i = 1; i < temps.length; i++) {
J10
}
J11

Answer key: J. Warm days

Order: J2, J6, J5, J9, J3, J7, J11, J1, J8, J4. Extra: J10

var temps = [75, 61, 58, 80, 77, 66];
onEvent("countButton", "click", function() {
	var count = 0;
	for (var i = 0; i < temps.length; i++) {
		if (temps[i] > 70) {
			count = count + 1;
		}
	}
	setText("countLabel", count + " warm days");
});

Extra strip: for (var i = 1; i < temps.length; i++) {. The first item is at index 0. Starting at 1 skips the 75, so the label shows 2 warm days.