# Thread: Let's Make A Deal

1. Registered User
Join Date
Oct 2009
Posts
2

## Let's Make A Deal

Hi, this is my first time posting here. I am working on a javascript assignment for a class and I'm having a lot of trouble. I have to make a javascript application that simulates the Let's Make A Deal game show.

http://web.stcloudstate.edu/aanda/cs200/hw2f09.html

These are the requirements for my website.

I keep getting "function is not defined" error for my Prize and GamePartOne functions. Actually all of these functions are getting this problem. It must be some sort of logic error or really stupid syntax error on my part. Please help me fix this.

Code:
<html>
<title>Orgath, assignment 2, csxxxxxx, October 24, 2009</title>

<script type="text/javascript" src="random.js"></script>

<script type="text/javascript">

function Prize()
//Assumes: 1 of 3 doors is selected.
//Results: This determines which prize is behind which door.
{

var game;

game = RandomInt(1, 3);

if (game == 1)
{
GamePartOne(pick, 1, 2, 2);
GamePartTwo(final1, 1, 2, 2);
}
else if (game == 2)
{
GamePartOne(pick, 2, 1, 2);
GamePartTwo(final1, 2, 1, 2);
}
else if (game == 3)
{
GamePartOne(pick, 2, 2, 1);
GamePartTwo(final1, 2, 2, 1);
}
else {
}
}

function GamePartOne(pick, door1, door2, door3)
//Assumes: variables door1, door2, and door3 have all been assigned 1 or 2 and pick has been assigned 1, 2 or 3.
//Returns: One door will be revealed and the user will be instructed to pick another another door.
{

var number;

if (1 == pick && 1 == door1)
{
number = RandomInt(1, 2);
if (1 == number)
{
ImgReveal(2, pick);
}
else
{
ImgReveal(3, pick);
}

}
else if (1 == pick && 1 != door1)
{
if (1 == door2)
{
ImgReveal(3, pick);
}
else
{
ImgReveal(2, pick);
}
}
else if (2 == pick && 1 == door2)
{
number = RandomInt(1, 2);
if (1 == number)
{
ImgReveal(1, pick);
}
else
{
ImgReveal(3, pick);
}
}
else if (2 == pick && 1 != door2)
{
if(1 == door1)
{
ImgReveal(3, pick);
}
else
{
ImgReveal(1, pick);
}
}
else if (3 == pick && 1 == door3)
{
number = RandomInt(1, 2);
if (1 == number)
{
ImgReveal(2, pick);
}
else
{
ImgReveal(1, pick);
}
}
else if (3 == pick && 1 != door3)
{
if(1 == door1)
{
ImgReveal(2, pick);
}
else
{
ImgReveal(1, pick);
}
}
else
{
}
}

function ImgReveal(reveal, pick)
//Assumes: The first door has been picked.
//Returns: One door is revealed, a new messege appears, and the onclick attributes change.
{

var dr1a, dr2a, dr3a;

dr1a = document.getElementById('dr1');
dr2a = document.getElementById('dr2');
dr3a = document.getElementById('dr3');

if (1 == reveal)
{
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
dr1a.onclick = "null";
dr2a.onclick = "GamePartTwo(2, door1, door2, door3); Counter(pick, 2, winlose)";
dr3a.onclick = "GamePartTwo(3, door1, door2, door3); Counter(pick, 3, winlose)";
document.getElementById('textBox').value = "You have picked door " + pick + ". Switch or stay by clicking on the doors.";
}
else if (2 == reveal)
{
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
dr1a.onclick = "GamePartTwo(1, door1, door2, door3); Counter(pick, 1, winlose)";
dr2a.onclick = "null";
dr3a.onclick = "GamePartTwo(3, door1, door2, door3); Counter(pick, 3, winlose)";
document.getElementById('textBox').value = "You have picked door " + pick + ". Switch or stay by clicking on the doors.";
}
else
{
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
dr1a.onclick = "GamePartTwo(1, door1, door2, door3); Counter(pick, 1, winlose)";
dr2a.onclick = "GamePartTwo(2, door1, door2, door3); Counter(pick, 2, winlose)";
dr3a.onclick = "null";
document.getElementById('textBox').value = "You have picked door " + pick + ". Switch or stay by clicking on the doors.";
}

}

function GamePartTwo(final1, door1, door2, door3)
//Assumes: One door has been revealed and the user has chosen to switch or stay.
//Returns: Notifies the user if they have won or lost and calls the Counter() function.
{

var dr1a, dr2a, dr3a;

dr1a = document.getElementById('dr1');
dr2a = document.getElementById('dr2');
dr3a = document.getElementById('dr3');

if (1 == final1)
{
if (1 == door1)
{
document.getElementById('textBox').value="You win! Click on a door to play again.";
Counter(pick, final1, 1);
document.getElementById('dr1').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
}
else
{
document.getElementById('textBox').value="You lose! Click on a door to play again.";
Counter(pick, final1, 2);
if (1 == door2)
{
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr2').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
}
else
{
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr3').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
}
}
}
else if (2 == final1)
{
if (1 == door2)
{
document.getElementById('textBox').value="You win! Click on a door to play again.";
Counter(pick, final1, 1);
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr2').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
}
else
{
document.getElementById('textBox').value="You lose! Click on a door to play again.";
Counter(pick, final1, 2);
if (1 == door1)
{
document.getElementById('dr1').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
}
else
{
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr3').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
}
}
}
else if (3 == final1)
{
if (1 == door3)
{
document.getElementById('textBox').value="You win! Click on a door to play again.";
Counter(pick, final1, 1);
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr3').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
}
else
{
document.getElementById('textBox').value="You lose! Click on a door to play again.";
Counter(pick, final1, 2);
if (1 == door2)
{
document.getElementById('dr1').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr2').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
}
else
{
document.getElementById('dr1').src = "http://www.clipartheaven.com/clipart/money/dollar.gif";
document.getElementById('dr2').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
document.getElementById('dr3').src = "http://etc.usf.edu/clipart/4700/4778/donkey_13_md.gif";
}
}
}
else
{
}

dr1a.onclick= "GameReset()";
dr2a.onclick= "GameReset()";
dr3a.onclick= "GameReset()";
}
Thank you
[EDIT: It was too long so I will post the second part below]

2. Registered User
Join Date
Dec 2002
Location
Pleasanton, CA
Posts
2,132
... "function is not defined" ...
Guess...
Javascript is case-sensitive.

3. Registered User
Join Date
Oct 2009
Posts
2
Originally Posted by Nedals
Guess...
Javascript is case-sensitive.
Okay... well I don't see where I made capitalization mistakes.

4. Registered User
Join Date
Oct 2008
Location
U.S.
Posts
726
First, a 'best practices' note, function and variable names should not generally start with a capital letter, that is usually reserved for constructor functions.
A few observations: within your 'Prize' function you refer to variables 'pick' and 'final1' which do not exist within that function or are not globally accessible near as I can see. Also in your 'GamePartTwo' function you appear to have the same problem with references in there to a 'pick' variable which I don't see defined anywhere's in that function. You do use them in ImgReveal and GamePartOne as function arguments, but are not defined in the other functions.
Also, setting of the onclicks is incorrect, within functions do not attempt to set onclick's to string values, rather define a function for the onclick, such as:
Code:
dr1a.onclick = function () { return false; };
dr2a.onclick = function () { GamePartTwo(2, door1, door2, door3); Counter(pick, 2, winlose); return false; };
And I don't see where winlose is defined in ImgReveal either... or door1 or door2 or door3...
Another little tip, don't know if you've covered objects yet or not, but this would be a good place to use a single string literal object, could contain all the functionality you need in one global object...
Last edited by astupidname; 10-26-2009 at 10:54 PM.

##### 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
•

"

"

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.10062 seconds
• Memory Usage 2,893KB
• Queries Executed 15 (?)
Template Usage (34):
• (2)bbcode_code
• (2)bbcode_quote
• (1)footer
• (1)forumjump
• (1)forumrules
• (1)gobutton
• (4)memberaction_dropdown
• (1)navbar
• (1)navbar_moderation
• (1)navbar_noticebit
• (1)navbar_tabs
• (2)option
• (4)postbit
• (4)postbit_onlinestatus
• (4)postbit_wrapper
• (1)spacer_close
• (1)spacer_open
• (1)tagbit_wrapper

Phrase Groups Available (6):
• global
• inlinemod
• postbit
• posting
• reputationlevel
Included Files (26):
• ./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 (70):
• 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