|
| 1 | +--- |
| 2 | +layout: base.html |
| 3 | +title: Simple HTML - Comparing things |
| 4 | +--- |
| 5 | +<section class="side-by-side"> |
| 6 | + <canvas class="game right" id="canvas" oncontextmenu="event.preventDefault()"></canvas> |
| 7 | + <div> |
| 8 | + <article> |
| 9 | + <h1>Comparing things</h1> |
| 10 | +<p>You can make a computer compare pieces of |
| 11 | + information and then do different things according to |
| 12 | + the results. To do this you use the commands <code class="command">IF</code> and |
| 13 | + <code class="command">THEN</code>. You can find out how <code class="command">IF</code> and <code class="command">THEN</code> work in the |
| 14 | + program below.</p> |
| 15 | +<pre> |
| 16 | +NEW |
| 17 | +10 CLS |
| 18 | +20 PRINT "TYPE IN TWO NUMBERS" |
| 19 | +30 INPUT A |
| 20 | +40 INPUT Z |
| 21 | +50 IF A=Z THEN PRINT "EQUAL" |
| 22 | +60 IF A<>Z THEN PRINT "NOT EQUAL" |
| 23 | +RUN |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> |
| 27 | + In this program the <code class="command">IF</code> and <code class="command">THEN</code> commands |
| 28 | + make the computer compare the numbers |
| 29 | + stored in the variables A and Z. If the |
| 30 | + numbers are the same the computer displays |
| 31 | + the message "EQUAL". If the numbers are |
| 32 | + different, the message is "NOT EQUAL". |
| 33 | +</p> |
| 34 | + |
| 35 | +<aside> |
| 36 | + The <code>=</code> symbol compares the numbers to see if they are the same. The <code><></code> symbol compare the numbers to see if they are different. |
| 37 | +</aside> |
| 38 | + |
| 39 | +<center><img src="{{ base_uri }}/img/usborne/simple-basic/img/09compare.png"></center> |
| 40 | + </article> |
| 41 | + |
| 42 | + <article> |
| 43 | + <h2>Comparing words</h2> |
| 44 | + <p> |
| 45 | +You can also use <code class="command">IF</code> and <code class="command">THEN</code> to |
| 46 | +make the computer compare words. |
| 47 | +Try running the program below. |
| 48 | +The <code class="command">IF</code> and <code class="command">THEN</code> commands make |
| 49 | +the computer compare the |
| 50 | +names stored in <code>S$</code> and |
| 51 | +<code>N$</code>, to see if they are the |
| 52 | +same or not. |
| 53 | + </p> |
| 54 | +<pre> |
| 55 | +NEW |
| 56 | +10 CLS |
| 57 | +20 S$="SLIMY SID" |
| 58 | +30 PRINT "WHAT'S YOUR NAME?" |
| 59 | +40 INPUT N$ |
| 60 | +50 IF N$<>S$ THEN PRINT "I CAN'T STAND MONSTERS CALLED "; N$ |
| 61 | +60 IF N$=S$ THEN PRINT "HELLO ";S$;" NICE TO MEET YOU" |
| 62 | +RUN |
| 63 | +</pre> |
| 64 | +</article> |
| 65 | +<article> |
| 66 | + <h2>Age program</h2> |
| 67 | + |
| 68 | +<p> |
| 69 | +When you type in this program, put your own age in line 20. Then let a friend run the |
| 70 | +program. The computer will work out whether your friend is older, younger or the same age as you. |
| 71 | +</p> |
| 72 | + |
| 73 | +<pre> |
| 74 | +NEW |
| 75 | +10 CLS |
| 76 | +20 A=11 |
| 77 | +30 PRINT "I AM";A;" YEARS OLD" |
| 78 | +40 PRINT "HOW OLD ARE YOU?" |
| 79 | +50 INPUT B |
| 80 | +60 IF A=B THEN PRINT "WE'RE THE SAME AGE!" |
| 81 | +70 IF A>B THEN PRINT "I'M OLDER THAN YOU" |
| 82 | +80 IF A<B THEN PRINT "I'M YOUNGER THAN YOU" |
| 83 | +RUN |
| 84 | +</pre> |
| 85 | + <footer> |
| 86 | + <a href="{{ base_uri }}/simple10" class="button">Next</a> |
| 87 | + </footer> |
| 88 | + </article> |
| 89 | + </div> |
| 90 | +</section> |
0 commit comments