www.webdeveloper.com
Results 1 to 3 of 3

Thread: Problem keeping score

Hybrid View

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    Problem keeping score

    I have made a website about math. There is a testjezelf page (test yourself) wiyh a 10 math problem. I need to keep the score. When i put an eqation in the answer (antwoord) he dosnt keep a record of the score. When i put a hard answer in he does keep the score...Help


    <script type="text/javascript">

    var imagelinks = new Array();
    var ry = Math.floor(Math.random()*myimages.length);
    //var ry = 0;
    var score = 0;

    var detekst = '';
    var antwoord = '';
    var antwoord2 = '';

    function random_imglink(){
    document.getElementById('plaatje').innerHTML = '<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'"></a>';
    }

    function mijnRekenApp() {

    //console.log("Start!");
    console.log("som" + ry);

    function random_imglink(){
    // plaatje = document.getElementById('plaatje');
    // document.plaatje.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'"></a>');

    document.getElementById('plaatje').innerHTML = '<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'"></a>';
    }

    if (ry == 0) {

    random_imglink(); // set image

    //var g1 = Math.floor(Math.random() * 10) + 1;
    var g1 = Math.floor(Math.random() * 10) + 1;;
    var g2 = g1 + g1;
    var g3 = 3.14;
    var antwoord = (g2) * (g3);
    var antwoord2 = (g1) * (g1) * (g3);
    document.getElementById('somveld').innerHTML = 'De straal is ' + g1 + ' . Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }


    } else if (ry == 1) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 1;
    var g2 = g1 + g1;
    var g3 = 3.14;
    var antwoord = (g2) * (g3);
    var antwoord2 = (g1) * (g1) * (g3);
    //var antwoord = 20; // voor score test
    //var antwoord2 = 20;
    document.getElementById('somveld').innerHTML = 'De diameter is ' + g2 + ' . Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }


    } else if (ry == 2) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 1;
    var g2 = g1 + 4;
    var g3 = g1 + 2;
    var g4 = g1 + 3;
    var antwoord = (g1) + (g2) + (g4);
    var antwoord2 = (g1) * (g3) / 2;
    document.getElementById('somveld').innerHTML = 'AB = ' + g1 + ' // AC = ' + g2 + ' // CD = ' + g3 + ' // BC = ' + g4 + '. Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }


    } else if (ry == 3) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 1;
    var g2 = g1 + 3;
    var g3 = g1 - 1;
    var g4 = g1 + 2;
    var antwoord = (g1) + (g2) + (g4);
    var antwoord2 = (g3) * (g4) / 2;
    document.getElementById('somveld').innerHTML = ' AB = ' + g1 + ' // BC = ' + g2 + ' // BD = ' + g3 + ' // AC = ' + g4 + '. Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }

    } else if (ry == 4) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 1;
    var g2 = g1 + 4;
    var g3 = g1 + 2;
    var g4 = g1 + 3;
    var antwoord = (g1) + (g2) + (g4);
    var antwoord2 = (g1) * (g3) / 2;
    document.getElementById('somveld').innerHTML = ' AB = ' + g1 + ' // BC = ' + g2 + ' // CD = ' + g3 + ' // AC = ' + g4 + '. Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }


    } else if (ry == 5) {

    random_imglink();

    var g1 = 8;
    var g2 = 10;
    var g3 = 6;
    var antwoord = (g1) + (g2) + (g3);
    var antwoord2 = (g1) * (g3) / 2;
    document.getElementById('somveld').innerHTML = 'AB = ' + g1 + ' // BC = ' + g2 + ' // AC = ' + g3 + ' . Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }

    } else if (ry == 6) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 4;
    var g2 = Math.floor(Math.random() * 10) + 3;
    var g3 = Math.floor(Math.random() * 10) + 1;
    var antwoord = (g1 * 2) + (g2 * 2);
    var antwoord2 = (g1) * (g3);
    document.getElementById('somveld').innerHTML = 'AB = ' + g1 + ' // BC = ' + g2 + ' // CE = ' + g3 + ' . Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }

    } else if (ry == 7) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 3;
    var g2 = Math.floor(Math.random() * 10) + 2;
    var g3 = Math.floor(Math.random() * 10) + 1;
    var antwoord = (g1 * 2) + (g2 * 2);
    var antwoord2 = (g1) * (g3);
    document.getElementById('somveld').innerHTML = ' AB = ' + g1 + ' // BC = ' + g2 + ' // DE = ' + g3 + ' . Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }


    } else if (ry == 8) {

    random_imglink();

    var g1 = Math.floor(Math.random() * 10) + 3;
    var g2 = Math.floor(Math.random() * 10) + 1;
    var g3 = Math.floor(Math.random() * 10) + 2;
    var antwoord = (g1 * 2) + (g2 * 2);
    var antwoord2 = (g1) * (g3);
    document.getElementById('somveld').innerHTML = ' AB = ' + g1 + ' // BC = ' + g2 + ' // BE = ' + g3 + ' . Bereken de omtrek en oppervlakte';

    function som() {
    document.getElementById('uitvoerveld').innerHTML = ' ';
    document.formulier.invoerveld.value = "";
    document.formulier.invoerveld.focus();
    }


    } // einde if

    invoer = parseFloat((document.formulier.invoerveld.value).split(',').join('.'));
    invoer2 = parseFloat((document.formulier.invoerveld2.value).split(',').join('.'));

    // SCORE BIJHOUDEN
    if ((invoer == antwoord) && (invoer2 == antwoord2)){
    score = score + 10;
    //ry = ry + 1; // hij gaat pas naar de volgende som als het antwoord goed is
    console.log(score);
    }
    ry = ry + 1; // hij gaat altijd naar de volgende som
    if(ry > 10){ // 10 = nu het aantal sommen
    ry = 0; // begin weer opniew
    }

    document.getElementById('scorebord').innerHTML= 'De score is <b>' + score + '</b>!!';
    console.log("score = " + score);

    } //mijnRekenApp

    // TIMER FUNCTIE

    var interval;
    var minutes = 15;
    var seconds = 5;

    //window.onload = function() {
    // countdown('countdown');
    //}

    function countdown(element) {

    // toon de verstopte knop
    var devolgendeknop= document.getElementById('next');
    devolgendeknop.style.display = "block";

    interval = setInterval(function() {
    var el = document.getElementById(element);
    if(seconds == 0) {
    if(minutes == 0) {
    el.innerHTML = "De tijd is om!";
    devolgendeknop.style.display = "none"; // verstop de volgende knop
    //window.location="score.html"; // redirect
    alert(score);
    clearInterval(interval);
    return;
    } else {
    minutes--;
    seconds = 60;
    }
    }
    if(minutes > 0) {
    var minute_text = minutes + (minutes > 1 ? ' minuten en' : ' minuut en');
    } else {
    var minute_text = '';
    }
    var second_text = seconds > 1 ? 'seconden' : 'second';
    el.innerHTML = minute_text + ' ' + seconds + ' ' + second_text + ' resterend';
    seconds--;
    }, 1000);
    }



    </script>





    www.interactive-art.nl

    What is wrong????

  2. #2
    Join Date
    Jan 2005
    Posts
    369
    I don't suppose that I am the only one that finds it a little difficult to read code that contains a foreign language (Dutch?)

    Could you give us an idea of which line you think is going wrong? Or at least where you see the issue appearing?
    I can see the score logged/displayed in several places, so not sure which part to concentrate on.

    And of course, what _do_ you see - does it come out blank, zero, NaN, undefined ...

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,360
    It helps if you use the [ CODE ] [ /CODE ] tags in the forum (without the spaces after and before the square brackets) for posting up JavaScript and HTML ones for HTML and PHP ones for PHP...

    It also helps if you include the document that you are using.

    From looking at it, the code can be vastly reduced by adding more functions to do tasks that are repeated several times.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles