PDA

View Full Version : return 0 if another variable is 0


ChrisVersion2
12-08-2008, 03:52 PM
Howdy Folks,

I'm trying to have var x equal zero if var y equals 0.

if var y is greater than 0 than war x will equal 240

This is the mess that I've coded. Novice level one I'm fully aware, any help or a direction would be great.


<script type="text/javascript">
var y = 15;
var x = wagemin;

wagemin()
{

if (wth <= 0)
{
return 0;
}
else
{
return 240;}
}
document.write(x)
</script>

RysChwith
12-09-2008, 08:23 AM
Shortest way:var y = 15;
var x = ( y == 0 ) ? 0 : 240;

document.write( x );This way is probably more instructive, however:var y = 15;
var x;

if( y == 0 ) {
x = 0;
} else {
x = 240;
}

document.write( x );Make sense?

Rys