#### Hybrid View

1. Registered User
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 ry = Math.floor(Math.random()*myimages.length);
//var ry = 0;
var score = 0;

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

}

function mijnRekenApp() {

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

// plaatje = document.getElementById('plaatje');

}

if (ry == 0) {

//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) {

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) {

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) {

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) {

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) {

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) {

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) {

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) {

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;

// 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
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. Registered User
Join Date
Jan 2005
Posts
375
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. 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.

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
•

"

"

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.09070 seconds
• Memory Usage 2,977KB
• Queries Executed 13 (?)
Template Usage (29):
• (1)footer
• (1)forumjump
• (1)forumrules
• (1)gobutton
• (3)memberaction_dropdown
• (1)navbar
• (1)navbar_moderation
• (1)navbar_noticebit
• (1)navbar_tabs
• (2)option
• (3)postbit
• (3)postbit_onlinestatus
• (3)postbit_wrapper
• (1)spacer_close
• (1)spacer_open
• (1)tagbit_wrapper

Phrase Groups Available (6):
• global
• inlinemod
• postbit
• posting
• reputationlevel
Included Files (27):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/functions_bigthree.php
• ./includes/class_postbit.php
• ./includes/class_bbcode.php
• ./includes/functions_reputation.php
• ./includes/functions_notice.php
• ./packages/vbattach/attach.php
• ./vb/types.php
• ./vb/cache.php
• ./vb/cache/db.php
• ./vb/cache/observer/db.php
• ./vb/cache/observer.php

Hooks Called (71):
• init_startup
• friendlyurl_resolve_class
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• strip_bbcode
• friendlyurl_clean_fragment
• friendlyurl_geturl
• forumjump
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates
• notices_check_start
• notices_noticebit
• process_templates_complete
• friendlyurl_redirect_canonical
• bbcode_fetch_tags
• bbcode_create
• postbit_factory
• postbit_display_start
• postbit_imicons
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• postbit_display_complete
• memberaction_dropdown
• tag_fetchbit_complete
• forumrules
• navbits
• navbits_complete