Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple logic question on switch

Status
Not open for further replies.

SkiCheif

Technical User
Sep 8, 2004
30
US
Background Information This is the bottom half of an if statement. I am trying to determine what the number of points that the wrestler won by and award him the proper point for the match and seeding.
Essentially there are three categories: Tech Fall, a Major and win by decision.

A decision is any win with 7 or less points between opponents.
A major is a win with between 8 and 14 points awarded to the winner
A tech fall happens when the wrestler wins with over 15 points in his favor.

Each level awards more points.

The problem that I am having is asking the switch to determine how many points.

I have assigned the point difference to the variable 'scorediff' and in the alert box it is telling me that the math part of this operation is working.

THE ISSUE: Nothing triggers except the default

I tried this also:

case scorediff < 7:
its a decision - do this code;
case scorediff < 14:
its a major - do this code;
default
its a tech fall - do this code;


Here is an example of my current code, please point out my mistake as I just can figure this one out so far.

Thanks!

Code:
								var scoredif = (vismatchscore-homematchscore)
							alert ("The visitor won")
							alert (scoredif)
							switch (scoredif)
							{
								case scoredif >= 1 && scoredif <=7:
								
									alert ("Vis win by decision");
									break;
								
								case scoredif >= 8 && scoredif <=14:
									
									alert ("Vis Win by Major");						
									break;
								
								default:
								
								
									alert ("Vis Win Tech Fall");
									//var userinput = prompt("Enter the time of the match in this format: 0000 (the program will insert the colon)");
									//window.document.match_information.txtMatchTime.value = userinput.slice(0,2) + ":" + userinput.slice(2,4);
									//window.document.match_information.txtHomeSeed.value = 1;
									//window.document.match_information.txtVisitingSeed.value = 6;
									//window.document.match_information.txtHomeMatch.value = 0;
									//window.document.match_information.txtVisitingMatch.value = 5;
									//window.document.match_information.txtHomeBoutOutcome.value = "Loss by Tech Fall";
									//window.document.match_information.txtVisitingBoutOutcome.value = "Win by Tech Fall";
									//window.document.match_information.cmdSubmit.focus()
									
									break;
							} //end of switch
 
Try this (comments removed)
Code:
switch (scoredif)
{
  case >= 1 && <=7:
    alert ("Vis win by decision");
    break;
  case scoredif >= 8 && scoredif <=14:
    alert ("Vis Win by Major");                        
    break;
  default:
    alert ("Vis Win Tech Fall");
    break;
}

Also, you can use a series of if...else if...else clauses.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Sorry Chessbot, no luck,

Any other suggestions?
I scoured the web for switch examples to find the one that put the variable on both sides of the comparitors.

This is so easy in VBA using the TO operator. (case 1 to 7)

The only way it works is if I assign one number to each case. I have tried all types of different ways including putting in the the variable, putting it in both spots, using OR logic and the like.

I am almost to the point where I will just put in 15 case statements! Might be easier! :)

Keith
 
Just go with if...else.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
I did and it works.

Thanks Chessbot your help on this and other questions has really been appreciated.

Keith
 
No problem.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
The problem is that you can't use < or > in a switch statement in Javascript. That's stuff from BASIC. You'd have to use something like:

switch (scoredif)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
{
alert ("Vis win by decision");
break;
}
case 8:
case 9:
case 10:
case 11:
case 13:
case 14:
{
alert ("Vis Win by Major");
break;
}
default:
{
alert ("Vis Win Tech Fall");
break;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top