// einewurzel.js
// erstellt am 15. Dezember 2006
// geändert am 22. Dezember 2006
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor


var score =0;
var geloest =0;

function reset(){
document.Para.vx2.value ="";
document.Para.vx3.value ="";
document.Para.vx4.value ="";
document.Para.wertung.value ="";

}

function zufall(min, max, ohne) {
  var zufallszahl;
  do {
  zufallszahl = Math.round(min + Math.random() * (max - min));
  } while (zufallszahl == ohne);
  return zufallszahl;
}

function hilfe() {
score = score - 20; if (score <0) score =0;
document.Para.points.value = "Aktueller Punktestand: "+String(score)+" Punkte";
document.Para.wertung.value = String(Math.pow(1,2))+" , "+
String(Math.pow(2,2))+" , "+
String(Math.pow(3,2))+" , "+
String(Math.pow(4,2))+" , "+
String(Math.pow(5,2))+" , \n"+
String(Math.pow(6,2))+" , "+
String(Math.pow(7,2))+" , "+
String(Math.pow(8,2))+" , "+
String(Math.pow(9,2))+" , \n"+
String(Math.pow(10,2))+" , "+
String(Math.pow(11,2))+" , "+
String(Math.pow(12,2))+" , "+
String(Math.pow(13,2))+"\n"+
"Diese Hilfe kostet 20 Punkte. Danke!";
}

function schreibe(){
reset();
geloest =0;
zahl1 = zufall(2,13);
if (zahl1<7) zahl2 = zufall(2,6,zahl1);
if (zahl1>6  && zahl1<12) zahl2 = zufall(2,4);
if (zahl1>11) zahl2 = 2;
if (zahl2==4) zahl2 = 3;
quadratzahl= Math.pow(zahl1,2);
erstezahl = quadratzahl*zahl2;

document.Para.vx2.value = "";;
document.Para.vx3.value = zahl1;
document.Para.vx4.value = zahl2;
document.Para.vx2.focus();

}

function pruefe()
{

if (document.Para.vx2.value !=""){
eingabe = document.Para.vx2.value.replace(",",".");
loesung = eval(eingabe);
}
else loesung =0;


if (geloest ==0) {

if (loesung == erstezahl) {
document.Para.wertung.value = "Ausgezeichnet, die Aufgabe ist gelöst! \n"+
    "Mit >>Neue Aufgabe erstellen<< \nkannst du weitermachen.";
    score=score+25;
    geloest = 1;
    }

   else {
   document.Para.wertung.value = "Leider falsch !\n Es ist: "+
   "wurzel("+String(zahl1)+ "² · "+String(zahl2)+")"+
   " = wurzel("+String(quadratzahl)+" · "+String(zahl2)+")\n"+
   "Somit lautet die Lösung: wurzel("+String(erstezahl)+")";
   score = score - 15; if (score <0) score =0;
   geloest = 1;
   }
   }

   else {
   document.Para.wertung.value = "Schwindeln unmöglich !\n Die Aufgabe war schon gelöst.\nDie Lösung war: "
   + String(zahl1)+ " · wurzel("+zahl2+") = wurzel("+String(erstezahl)+")";
   score = score - 5; if (score <0) score =0;
}



document.Para.points.value = "Aktueller Punktestand: "+String(score)+" Punkte";
}

function auswerten() {

var punkte = score;
if (punkte < 1) punkte = 1;
// Zurücksetzen der Punkte auf Ausgangswert


score =0;
geloest =1;

document.Para.vx2.value ="";
document.Para.vx3.value ="";
document.Para.vx4.value ="";

text1 ="";
text2 ="Deine Punkte werden nun übertragen. \n";
text3 ="Damit werden sie hier gelöscht. \n";
text4="Du beginnst also wieder bei 0 Punkten.";
text5="";
text = text1+text2+text3+text4+text5;
document.Para.wertung.value = text;

/* Achtung muss für jede Datei manuell angepasst werden */
/*                     Anfang                           */
var aufgabenart="Unter eine Wurzel schreiben";
var datnam= "highsqlpost94ww.php";
uebertrag = "<form name = 'eingabe' action ='../../../Mathematik/"+datnam+"' method ='post'>";
auswertung(aufgabenart,punkte,uebertrag);
/*                     Ende                           */
}

