var hundredTimes = []; var twoHundredTimes = []; var selection; onEvent("addButton", "click", function( ) { selection = getText("distances"); if (selection == "100 Meter") { appendItem(hundredTimes, Number(getText("input"))); setText("hundredTextArea", hundredTimes.join(", ")); } else { appendItem(twoHundredTimes, Number(getText("input"))); setText("twoHundredTextArea", twoHundredTimes.join(", ")); } }); onEvent("fastButton", "click", function( ) { selection = getText("distances"); if (selection == "100 Meter") { setText("hundredTextArea", fastestTime(hundredTimes)); } else { setText("twoHundredTextArea", fastestTime(twoHundredTimes)); } }); function fastestTime(times) { var fastest = times[0]; for (var i = 0; i < times.length; i++) { if (fastest > times[i]) { fastest = times[i]; } } return "Your fastest time is: " + fastest; }