Forum Moderators: open
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>
(condition) [b]?[/b] (return this if condition is true) [b]:[/b] (return this if condition is false)thus your problem can be reduced to one simple expression, no function required:
x = (y>0) ? 240 : 0;
in pseudo-english pseudo-code, it's doing this:
assign to x the result of this operation:
is y greater than 0?
if true, return 240.
if false, return 0.
hence x will be 0 when y is 0 or less (including negative numbers).