CodingJavascript help

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  koswix  
 To:  ANT_THOMAS     
37533.41 In reply to 37533.34 

You can buy it on the Market for £1.99 when it's done :C

 

(pete, you can have the 99p)



GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  koswix     
37533.42 In reply to 37533.41 
I haven't bought an app yet!

0/0
 Reply   Quote More 

 From:  koswix  
 To:  ANT_THOMAS     
37533.43 In reply to 37533.42 
Then you are dead to me :C


GIVE ME MEAT! :@ msg:37418.1
0/0
 Reply   Quote More 

 From:  Wattsy (SLAYERPUNX)   
 To:  ALL
37533.44 
Another quicky for you clever people

I have writen this function but I think I have it wrong.
It is supposed to prompt for a number between 1 and 3 and then alert if they enter anything else other than 1 2 or 3.

This is what I have got and it works to a fashion (1980's hairstylee wrong fashion that is) anyone help?

code:
function getChosenNumber()
{
	numberChosen=
    window.prompt('Player ' + currentPlayer + ' please choose a number between 1 and 3.','');
	if (numberChosen > 3)
	{
	   alert('please chose a number between 1 and 3');
    }
	return numberChosen
}

Web Shite Mail Me

0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  Wattsy (SLAYERPUNX)      
37533.45 In reply to 37533.44 
For s start, I'd have the decision point as:
code:
if (numberChosen < 1 || numberChosen > 3)
To prevent negative numbers. You're missing the semi-colon after the return statement. Other than that, I have no clue. In what way is it not working?

bastard by name, bastard by nature

0/0
 Reply   Quote More 

 From:  Wattsy (SLAYERPUNX)   
 To:  99% of gargoyles look like (MR_BASTARD)     
37533.46 In reply to 37533.45 

The problem, good sir, is that I have failed. Failed this program with the lack of skill of the programmer. Failed to the max infact.

 

Well actually, the problem is that even if it alerts the user they have put in a wrong number it still takes it off the original number of sticks.

 

Not to worry I am going to have to spend some time playing with it.

 

Cheers

Web Shite Mail Me

0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  Wattsy (SLAYERPUNX)      
37533.47 In reply to 37533.46 
Ah, yes, I see now. If the number is outside the range the alert pops up, but the next line is executed nonetheless.
Try sticking this line below the alert:
code:
return false;
Or, preferably, adding an else clause:
code:
function getChosenNumber()
{
	numberChosen=
    window.prompt('Player ' + currentPlayer + ' please choose a number between 1 and 3.','');
	if (numberChosen < 1 || numberChosen > 3)
	{
	   alert('please choose a number between 1 and 3');
	   return false;
    } else
	   {
	return numberChosen;
	   }
}
 

bastard by name, bastard by nature

0/0
 Reply   Quote More 

Reply to All    
 

1–20  21–40  41–47

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats