Hallo,
ich habe eine Newbie-Problem und ich hoffe ihr könnt mir helfen
1. Ich habe 2 Produkte als Array mit jeweils 7 Feldern definiert:
var product1 = new Array(ergebnis1[0], 0, xxx, yyy, 0, 0, false);
var product2 = new Array(ergebnis2[0], 0, 10, 200, 0, 0, false);
Dabei ist das 3. Feld bei Produkt 1 die Variable xxx und das 4. Feld bei Produkt 1 die Variable yyy.
2. Abfrage der Variablen
xxx = window.prompt("Bitte geben Sie untere Grenze ein", "");
yyy = window.prompt("Bitte geben Sie obere Grenze ein", "");
3. Ich will nun, wenn eine Bedingung erfüllt ist, eigentlich nur den Mittelwert aus xxx und yyy berechnen.
if (product1[1] == 0) product1[4] = Math.round((xxx + yyy) / 2);
if (product2[1] == 0) product2[4] = Math.round((product2[2] + product2[3]) / 2);
4. Problem: Ich bekomm, wenn ich xxx und yyy abfrage, kein sinnvolles Ergebnis. Wenn ich beispielsweise xxx = 20 sowie yyy = 50 eingebe, dann rechnet das Programm xxx = 20 / 2 = 10 und yyy = 50 / 2 = 25 und gibt aus: 1025. Ich hätte aber gern (20+50)/2 = 35 ausgegeben gehabt. Wo liegt das Problem?
ich habe eine Newbie-Problem und ich hoffe ihr könnt mir helfen
1. Ich habe 2 Produkte als Array mit jeweils 7 Feldern definiert:
var product1 = new Array(ergebnis1[0], 0, xxx, yyy, 0, 0, false);
var product2 = new Array(ergebnis2[0], 0, 10, 200, 0, 0, false);
Dabei ist das 3. Feld bei Produkt 1 die Variable xxx und das 4. Feld bei Produkt 1 die Variable yyy.
2. Abfrage der Variablen
xxx = window.prompt("Bitte geben Sie untere Grenze ein", "");
yyy = window.prompt("Bitte geben Sie obere Grenze ein", "");
3. Ich will nun, wenn eine Bedingung erfüllt ist, eigentlich nur den Mittelwert aus xxx und yyy berechnen.
if (product1[1] == 0) product1[4] = Math.round((xxx + yyy) / 2);
if (product2[1] == 0) product2[4] = Math.round((product2[2] + product2[3]) / 2);
4. Problem: Ich bekomm, wenn ich xxx und yyy abfrage, kein sinnvolles Ergebnis. Wenn ich beispielsweise xxx = 20 sowie yyy = 50 eingebe, dann rechnet das Programm xxx = 20 / 2 = 10 und yyy = 50 / 2 = 25 und gibt aus: 1025. Ich hätte aber gern (20+50)/2 = 35 ausgegeben gehabt. Wo liegt das Problem?