Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-19-2014, 02:16 PM   #1
Baseband Member
 
Join Date: Jul 2014
Location: USA
Posts: 29
Default HTML function not working?

I have created a function to take someone through a short series of questions, but when I try to push the button on the webpage it does nothing. I have gone through it a couple of times and have been unable to see where I have gone wrong. Here is the code for the function:

function womenTrivia();
{
var count = 0;
Meg();

function Meg();
{
var questionMeg = window.prompt("Who does Meg marry?");
var sentMeg = 'John Brooke';

window.prompt("Who does Meg marry?");

if(questionMeg != sentMeg)
{
questionMeg = window.prompt("Who does Meg marry?");
}
else
{
count = count + 1;
window.alert("You are Correct!");
}
if(count == 1)
{
Jo();
}
}
function Jo();
{
var questionJo = window.prompt("Where does Jo travel to pursue a literary career?");
var sentJo = 'New York City';

window.prompt("What does Jo travel to pursue a literary career?");

if(questionJo != sentJo)
{
questionJo = window.prompt("Where does Jo travel to pursue a literay career?");
}
else
{
count = count + 1;
window.alert("You are Correct!");
}
if(count == 2)
{
Beth();
}
}
function Beth();
{
var questionBeth = window.prompt("What causes Beth's health to deteriorate?");
var sentBeth = 'Scarlet Fever';

window.prompt("What causes Beth's health to deteriorate?");

if(questionBeth != sentBeth)
{
questionBeth = window.prompt("What causes Beth's health to deteriorate?");
}
else
{
count = count + 1;
window.alert("You are Correct!");
}
if(count == 3)
{
Amy();
}
}
function Amy();
{
var questionAmy = window.prompt("Is Amy the youngest sister, True or False?");
var sentAmy = 'True';

window.prompt("Is Amy the youngest sister, True or False?");

if(questionAmy != sentAmy)
{
questionAmy = window.prompt("Is Amy the youngest sister, True or False?");
}
else
{
count = count + 1;
window.alert("You are Correct!");
}
if(count == 4);
{
window.alert("Congratulations, you have finished the Trivia!");
}
}
}


And this is the code for the button to be pressed on the screen:

<p><input type="button" onclick="womenTrivia();" value="Little Women Trivia" class="auto-style4" style="width: 172px; height: 25px;"></p>
__________________

megan1989 is offline   Reply With Quote
Old 11-20-2014, 07:49 AM   #2
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: HTML function not working?

I haven't run this to check yet, but two mistakes I can see straight off:

- You seem to have all your functions *inside* the womenTrivia() function - they should all be separate. i.e. close the womenTrivia function (with a curly bracket) before the Meg() function starts (and delete the curly bracket at the end of the code to make it line up.)

- You shouldn't put a semi-colon after function headers, so when you have:

function Meg();
{
...etc

It should be:

function Meg()
{
...etc.
__________________

__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 11-20-2014, 11:37 AM   #3
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: HTML function not working?

I ran this through a debugger, and got 11 errors. (Though we all know that one can cause quite a few...)
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 11-20-2014, 11:38 AM   #4
Baseband Member
 
Join Date: Jul 2014
Location: USA
Posts: 29
Default Re: HTML function not working?

Thank you Berry, I thought that there may have been a way to be able to call all of those functions within a master function, so to speak. Apparently not, anyway I made the corrections that you suggested and it is working correctly now. Thank you
megan1989 is offline   Reply With Quote
Old 11-21-2014, 06:53 PM   #5
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: HTML function not working?

I am glad that you found help here.
If you have any other questions, you know where to find us.
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 11-22-2014, 02:16 AM   #6
..m.0,0.m..
Site Team
 
iPwn's Avatar
 
Join Date: May 2010
Location: USA
Posts: 3,870
Default Re: HTML function not working?

Try dis.

Code:
<script>
function womenTrivia() { 
var score = 0;
var possible = 4;

score += prompt("Who does Meg marry?") == "John Brooke" ? 1 : 0;
score += prompt("Where does Jo travel to pursue a literary career?") == "New York City" ? 1 : 0;
score += prompt("What causes Beth's health to deteriorate?") == "Scarlet Fever" ? 1 : 0;
score += prompt("Amy is the youngest sister. True or False?") == "True" ? 1 : 0;

alert("Congratulations! You have finished. \n\nYou scored " + score + " points \nOut of a possible " + possible);
} 
</script>

<button onclick="womenTrivia()">Little Women Trivia</button>
__________________
Me: You'd think as the dominant species we wouldn't be so effing stupid.
J: We're just intelligent enough to be completely effing stupid.
iPwn is offline   Reply With Quote
Old 11-22-2014, 01:03 PM   #7
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: HTML function not working?

The code tag is painful to look at. Perhaps a quote tag in the future?
__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Old 11-22-2014, 01:58 PM   #8
..m.0,0.m..
Site Team
 
iPwn's Avatar
 
Join Date: May 2010
Location: USA
Posts: 3,870
Default Re: HTML function not working?

Quote:
Originally Posted by Draygoes View Post
The code tag is painful to look at. Perhaps a quote tag in the future?
Quote will wrap the text, making it more painful to look at for a developer. Code is so you can copy/paste/maintain formatting standards... for, you know... code.

__________________
Me: You'd think as the dominant species we wouldn't be so effing stupid.
J: We're just intelligent enough to be completely effing stupid.
iPwn is offline   Reply With Quote
Old 11-22-2014, 02:29 PM   #9
Fully Optimized
 
Draygoes's Avatar
 
Join Date: Nov 2014
Location: United States
Posts: 1,653
Default Re: HTML function not working?

Fair enough, but I personally enjoy rapped text unless I am working in and IDE.
__________________

__________________
Will have a youtube channel up soon. Link will be here if I remember.
Draygoes is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 12:11 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0