This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-12-12 18:23:55

thelasthorizon
Scratcher
Registered: 2008-08-19
Posts: 100+

I Need Help

I was wondering if there was a way to figure out if a number is even or odd. I really need this for my project so please reply.

Offline

 

#2 2008-12-12 18:30:08

big-bang
Scratcher
Registered: 2008-02-21
Posts: 1000+

Re: I Need Help

Sorry, I don't think so. You could try to hack Scratch but I have no idea how.


http://i47.tinypic.com/6edrbm.jpghttp://i45.tinypic.com/dw9hmw.jpghttp://i50.tinypic.com/f28tvn.jpghttp://i45.tinypic.com/ruwaop.jpg

Offline

 

#3 2008-12-12 18:45:11

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: I Need Help

thelasthorizon wrote:

I was wondering if there was a way to figure out if a number is even or odd. I really need this for my project so please reply.

Yep! I'm not sure if this is the simplest way, but it works!

<when green flag clicked>
<forever>
<repeat until> << <( <{ number }> <=> 2 )> <or>  <( <{ number }> <<> 2 )>>>
<set{ number }to((( <{number }> <-> 2 ))
<if> <( <{ number  }> <=> 2 )>
<say[ It is even!
<else>
<say[ It is odd!

I hope this helps!

Offline

 

#4 2008-12-12 19:05:55

Zelda123
Scratcher
Registered: 2007-11-21
Posts: 1000+

Re: I Need Help

If X mod 2 = 0, number is even, else
Number is odd

Offline

 

#5 2008-12-13 15:43:52

big-bang
Scratcher
Registered: 2008-02-21
Posts: 1000+

Re: I Need Help

Wait! New idea!

[If [[number] divided by [[number] divided by 2]] equals 2]
broadcast EVEN
else?
broadcast ODD


http://i47.tinypic.com/6edrbm.jpghttp://i45.tinypic.com/dw9hmw.jpghttp://i50.tinypic.com/f28tvn.jpghttp://i45.tinypic.com/ruwaop.jpg

Offline

 

#6 2008-12-14 03:57:07

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: I Need Help

Using the mod block is the simplest way.
  [blocks](( number <mod> 2 ))[/blocks]

(number) MOD (2) will give an answer of zero if the number is even, or 1 if the number is odd.

Last edited by Mayhem (2008-12-14 03:58:56)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

Board footer