Rated 4 out of 5 stars

-OPEN-title-CLOSE-Übungsaufgabe Arrays - Der Wetterdienst-OPEN-/title-CLOSE-
-OPEN-script type="text/javascript"-CLOSE-
/* -OPEN-![CDATA[ */
var tagestempJuniKoeln = new Array(30);
tagestempJuniKoeln[0] = 20;
tagestempJuniKoeln[1] = 20;
tagestempJuniKoeln[2] = 20;
tagestempJuniKoeln[3] = 20;
tagestempJuniKoeln[4] = 21;
tagestempJuniKoeln[5] = 21;
tagestempJuniKoeln[6] = 21;
tagestempJuniKoeln[7] = 21;
tagestempJuniKoeln[8] = 21;
tagestempJuniKoeln[9] = 21;
tagestempJuniKoeln[10] = 21;
tagestempJuniKoeln[11] = 21;
tagestempJuniKoeln[12] = 21;
tagestempJuniKoeln[13] = 21;
tagestempJuniKoeln[14] = 21;
tagestempJuniKoeln[15] = 22;
tagestempJuniKoeln[16] = 22;
tagestempJuniKoeln[17] = 22;
tagestempJuniKoeln[18] = 22;
tagestempJuniKoeln[19] = 22;
tagestempJuniKoeln[20] = 22;
tagestempJuniKoeln[21] = 22;
tagestempJuniKoeln[22] = 22;
tagestempJuniKoeln[23] = 22;
tagestempJuniKoeln[24] = 22;
tagestempJuniKoeln[25] = 22;
tagestempJuniKoeln[26] = 22;
tagestempJuniKoeln[27] = 23;
tagestempJuniKoeln[28] = 23;
tagestempJuniKoeln[29] = 24;

function tagesTemp(){
var tag = window.prompt("Für welchen Tag im Juni wünschen Sie eine Vorhersage der Höchsttemperatur in Köln?","1");
document.write("Am "+ tag + ". Juni soll es " + tagestempJuniKoeln[tag-1] + "°C werden.");
//durch den Beginn des Index mit 0 muss bei dem Zugriff auf das Array eine 1 abgezogen werden
}

function hoechsteTagesTemp(temp){
var maxTemp = temp[0];

for (var i = 1; i-OPEN- temp.length;i++){
if (maxTemp -OPEN- temp[i]){
maxTemp = temp[i];
}
}
return maxTemp;
}
//Aufgrund der globalen Variable tagestempJuniKoeln könnte die Parameterliste auch leer bleiben
//Besser ist es allerdings, die Werte explizit in der Parameterliste zu übergeben, damit
//ein Anwender der Funktion auch sehen kann, welche Daten die Funktion für ihre Arbeit braucht
function ausgabeTemperaturen(temp){
document.write("-OPEN-h1-CLOSE-Voraussichtliche Temperaturen im Juni-OPEN-"+"/h1-CLOSE-");
for (var i=0; i -OPEN- temp.length;i++){
document.write(i+1 + ". Juni 2010: "+ temp[i] + "°C -OPEN-br /-CLOSE-");
}
}

//Testen der geschriebenen Funktionen

ausgabeTemperaturen(tagestempJuniKoeln);
tagesTemp();
document.write("-OPEN-br /" +"-CLOSE-");
document.write("Die hoechste Tagestemperatur im Juni wird " + hoechsteTagesTemp(tagestempJuniKoeln) + "°C.");
/* ]]-CLOSE- */
-OPEN-/script-CLOSE-

-OPEN-/head-CLOSE-

-OPEN-body-CLOSE-
-OPEN-/body-CLOSE-
-OPEN-/html-CLOSE-