|
Answer» I'm learning JavaScript (with the aid of online tutorials) and can't figure out where I messed up. This is what I have and where the problem seems to be:
<script type="text/javascript"> var apples = 10; alert('There are currently ' + apples + ' apples!');
var toss = prompt('How many apples would you like to throw at the doctor?', '0');
var thrown = parseInt(toss); if(thrown > apples){ alert('Sorry, but there are not that many apples. You can not throw ' + thrown + ' apples!'); } else { if(apples - thrown = 1){ alert('Now there is only one APPLE LEFT to throw!'); } else {apples -= thrown; alert('Now there are only ' + apples + ' apple(s) left to throw!'); } } </script>
Is there some weird rule about having if/else statements within other if/else statements? Or did I mess up in my ignorance elsewhere?
Any help would be greatly appreciated.you're missing an EQUALS when checking if there's only one apple left change to this: if(apples-thrown==1)Thanks a million. I had no clue I had to use a double =, that'll be QUITE helpful not only with this script but with many others in the future. Thank you again.
|