Beispiel 7 Angabe


Aufgabe 6 soll insofern abgeändert werden, dass so wie in http://www.testedich.de/quiz24/quiz/1195378536/Programmierer-Quiz der Benutzer nur 20 Sekunden Zeit hat die Frage zu beantworten. Nach diesen 20 Sekunden wird zur nächsten Frage weitergeschaltet.

Folgender Link sollte Ihnen bei der Implementierung des Timers helfen: http://www.w3schools.com/js/js_timing.asp




VIEL ERFOLG!

 

LÖSUNG:

HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script type="text/javascript" src="beispiel-7-loesung.js">
</script>
</head>
<body>
<form name="Formular">
<frage id="frage"></frage>
</form>
<script type="text/javascript">naechsteFrage(1);</script>
</body>

</html>

 

JS:

var anzahlRichtigeAntworten = 20;
var counter;
var t;
var seitenNummer = 1;

function auswerten()
{
if (radioButtonValue(document.Formular.frage10) == "d") anzahlRichtigeAntworten++;
document.getElementById('ausgabe').innerHTML = anzahlRichtigeAntworten + ' von 10 Fragen wurden richtig beantwortet.';
}


function radioButtonValue(feld)
{
for (i=0; i < feld.length; i++)
{
if(feld[i].checked == true)
{
return feld[i].value;
}
}
}


function naechsteFrage(nummer)
{
seitenNummer = nummer;
if (nummer == 1)
{
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 1: Was bedeutet HTML? <br/>' + randomConcat3('<input type="radio" name="frage1" value="a">Hypertext Markup Language</input> <br/>', '<input type="radio" name="frage1" value="b">Es gibt keine Abkürzung ;)</input> <br/>', '<input type="radio" name="frage1" value="c">Was ist das? </input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(2)">weiter</button>';
counter = 20;
doTimer();
}
if (nummer == 2)
{
if (radioButtonValue(document.Formular.frage1) == "a") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 2: Zu was wird CSS hauptsächlich verwendet? <br/>' + randomConcat3('<input type="radio" name="frage2" value="a">Es ist eine reine Text-Sprache/ Nichts mit Design!</input> <br/>', '<input type="radio" name="frage2" value="b">Nur zum Designerstellen</input> <br/>', '<input type="radio" name="frage2" value="c">Zum Positionieren von verschiedenen Dingen</input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(3)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 3)
{
if (radioButtonValue(document.Formular.frage2) == "c") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 3: Sie müssen ein Login-Script schreiben. Was für Sprachen SIND NOTWENDIG? <br/>' + randomConcat5('<input type="radio" name="frage3" value="a">Java Script + CSS</input> <br/>', '<input type="radio" name="frage3" value="b">HTML + PHP</input> <br/>', '<input type="radio" name="frage3" value="c">HTML + Java Script</input> <br/>', '<input type="radio" name="frage3" value="d">CSS + HTML</input> <br/>', '<input type="radio" name="frage3" value="e">NUR JAVA</input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(4)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 4)
{
if (radioButtonValue(document.Formular.frage3) == "b") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 4: In welcher Sprache werden die Befehle geschrieben, z.B. um irgendetwas in eine Tabelle einzufügen? <br/>' + randomConcat5('<input type="radio" name="frage4" value="a">MYSQL</input> <br/>', '<input type="radio" name="frage4" value="b">PHP</input> <br/>', '<input type="radio" name="frage4" value="c">Java-Script</input> <br/>', '<input type="radio" name="frage4" value="d">SQL</input> <br/>', '<input type="radio" name="frage4" value="e">HTML</input> <br/>') +'<br/> <br/> <button type="button" onclick="naechsteFrage(5)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 5)
{
if (radioButtonValue(document.Formular.frage4) == "d") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 5: In welcher Sprache besteht der Befehlt echo"";? <br/>' + randomConcat3('<input type="radio" name="frage5" value="a">CSS</input> <br/>', '<input type="radio" name="frage5" value="b">HTML</input> <br/>', '<input type="radio" name="frage5" value="c">PHP</input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(6)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 6)
{
if (radioButtonValue(document.Formular.frage5) == "c") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 6: Was macht der Befehl a href=""? <br/>' + randomConcat4('<input type="radio" name="frage6" value="a">Einen Link</input> <br/>', '<input type="radio" name="frage6" value="b">Gibt einen Text aus</input> <br/>', '<input type="radio" name="frage6" value="c">Gar nichts, ist falsch</input> <br/>', '<input type="radio" name="frage6" value="d">Positioniert ein Fenster</input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(7)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 7)
{
if (radioButtonValue(document.Formular.frage6) == "c") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 7: Was passiert, wenn man einfach in den Body eines HTML-Dokuments Text schreibt? <br/>' + randomConcat3('<input type="radio" name="frage7" value="a">Es geht nicht</input> <br/>', '<input type="radio" name="frage7" value="b">Es gibt ihn aus</input> <br/>', '<input type="radio" name="frage7" value="c">Es kommt eine Fehlermeldung</input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(8)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 8)
{
if (radioButtonValue(document.Formular.frage7) == "b") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 8: Braucht man für PHP einen Client? <br/>' + randomConcat4('<input type="radio" name="frage8" value="a">NEIN</input> <br/>', '<input type="radio" name="frage8" value="b">JA</input> <br/>', '<input type="radio" name="frage8" value="c">Nette Fangfrage ^^</input> <br/>', '<input type="radio" name="frage8" value="d">Was ist ein Client?</input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(9)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 9)
{
if (radioButtonValue(document.Formular.frage8) == "b") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 9: Wo ist der Fehler?<br/> $Hallo = "1";<br/> $Hallo2 ="2";<br/> Echo"$Hallo" <br/>' + randomConcat5('<input type="radio" name="frage9" value="a">Es müssen bei dem Echo die "" weg.</input> <br/>', '<input type="radio" name="frage9" value="b">Es fehlen die Semikolons bei dem Echo</input> <br/>', '<input type="radio" name="frage9" value="c">Es müssen die Semikolons bei den Variablen weg</input> <br/>', '<input type="radio" name="frage9" value="d">Es müssen bei den Variablen die "" weg.</input> <br/>', '<input type="radio" name="frage9" value="e">Ich hab keine Ahnung! </input> <br/>') + '<br/> <br/> <button type="button" onclick="naechsteFrage(10)">weiter</button>';
counter = 20;
clearTimeout(t);
doTimer();
}
if (nummer == 10)
{
if (radioButtonValue(document.Formular.frage9) == "b") anzahlRichtigeAntworten++;
document.getElementById('frage').innerHTML = '<label id="countDownText"></label> <br/> <br/> Frage 10: &lt;input type=&quot;button&quot; value=&quot;:)&quot; onclick=&quot;append(&#039;text&#039;, &#039;:) &#039;&quot; /&gt; <br/> Wo ist hier der Fehler? <br/>' + randomConcat5('<input type="radio" name="frage10" value="a">Der Strich vor dem &gt; gehört weg.</input> <br/>', '<input type="radio" name="frage10" value="b">Es fehlt eine öffnende Klammer</input> <br/>', '<input type="radio" name="frage10" value="c">Keine Ahnung....</input> <br/>', '<input type="radio" name="frage10" value="d">Es fehlt eine schließende Klammer</input> <br/>', '<input type="radio" name="frage10" value="e">Der Code passt</input> <br/>') + '<br/> <br/> <button type="button" onclick="auswerten()">auswerten</button> <br/> <br/> <label id="ausgabe"></label><br />';
counter = 20;
clearTimeout(t);
doTimer();
}
}


function GetRandom(min, max)
{
return min + parseInt(Math.random() * (max-min+1));
}


function randomConcat3(a, b, c)
{
var orderNr = GetRandom(1,6);
if (orderNr == 1) return a+b+c;
if (orderNr == 2) return a+c+b;
if (orderNr == 3) return b+a+c;
if (orderNr == 4) return b+c+a;
if (orderNr == 5) return c+a+b;
if (orderNr == 6) return c+b+a;
}


function randomConcat4(a, b, c, d)
{
var retVal;
var posA;
var posB;
var posC;
var posD;
posA = GetRandom(1,4);
posB = posA;
while (posB == posA)
{
posB = GetRandom(1,4);
}
posC = posA;
while (posC == posA || posC == posB)
{
posC = GetRandom(1,4);
}
posD = posA;
while (posD == posA || posD == posB || posD == posC)
{
posD = GetRandom(1,4);
}
if (posA == 1) retVal = a;
if (posB == 1) retVal = b;
if (posC == 1) retVal = c;
if (posD == 1) retVal = d;
if (posA == 2) retVal += a;
if (posB == 2) retVal += b;
if (posC == 2) retVal += c;
if (posD == 2) retVal += d;
if (posA == 3) retVal += a;
if (posB == 3) retVal += b;
if (posC == 3) retVal += c;
if (posD == 3) retVal += d;
if (posA == 4) retVal += a;
if (posB == 4) retVal += b;
if (posC == 4) retVal += c;
if (posD == 4) retVal += d;
return retVal;
}


function randomConcat5(a, b, c, d, e)
{
var retVal;
var posA;
var posB;
var posC;
var posD;
var posE;
posA = GetRandom(1,5);
posB = posA;
while (posB == posA)
{
posB = GetRandom(1,5);
}
posC = posA;
while (posC == posA || posC == posB)
{
posC = GetRandom(1,5);
}
posD = posA;
while (posD == posA || posD == posB || posD == posC)
{
posD = GetRandom(1,5);
}
posE = posA;
while (posE == posA || posE == posB || posE == posC || posE == posD)
{
posE = GetRandom(1,5);
}
if (posA == 1) retVal = a;
if (posB == 1) retVal = b;
if (posC == 1) retVal = c;
if (posD == 1) retVal = d;
if (posE == 1) retVal = e;
if (posA == 2) retVal += a;
if (posB == 2) retVal += b;
if (posC == 2) retVal += c;
if (posD == 2) retVal += d;
if (posE == 2) retVal += e;
if (posA == 3) retVal += a;
if (posB == 3) retVal += b;
if (posC == 3) retVal += c;
if (posD == 3) retVal += d;
if (posE == 3) retVal += e;
if (posA == 4) retVal += a;
if (posB == 4) retVal += b;
if (posC == 4) retVal += c;
if (posD == 4) retVal += d;
if (posE == 4) retVal += e;
if (posA == 5) retVal += a;
if (posB == 5) retVal += b;
if (posC == 5) retVal += c;
if (posD == 5) retVal += d;
if (posE == 5) retVal += e;
return retVal;
}


function doTimer()
{
document.getElementById('countDownText').innerHTML='Restliche Zeit in Sekunden zum Beantworten der Frage: ' + counter;
if (counter > 0)
{
counter--;
t=setTimeout("doTimer()",1000);
}
else
{
if (seitenNummer == 10)
{
auswerten();
}
else
{
naechsteFrage(seitenNummer+1);
}
}
}