3.6: Personality Quiz

Ok, enough of all these tiny little programmes designed for learning. Let's build something proper. Let's build a full-blown personality test!

First of all, we are going to have to learn a couple more new BASIC commands to help us get it just right.

The first new command we will learn is CLS.

CLS

This command is dead simple. It simply tells BASIC to clear the screen. Try opening a new BASIC tab, or refreshing the browser in your current tab, so you get this screen again:

SoC Computer 32K
 
BASIC
 
>

Now let's give it a try. Type CLS into BASIC like this:

SoC Computer 32K
 
BASIC
 
>CLS

Hit ENTER and see what happens.

Well look at that, it cleared everything from the screen. Now you have this:

>

You can still carry on doing things with BASIC, all it did was clear all text that was there already. So you can now still do this, give it a go:

>PRINT "HI"
HI
>

When used within a programme, CLS does that exact same thing. Try this:

>PRINT "HI"
HI
>10 CLS
>20 PRINT "HELLO THERE"
>

Now try RUNning it:

>PRINT "HI"
HI
>10 CLS
>20 PRINT "HELLO THERE"
>RUN

And you get this:

HELLO THERE
>

See what happened? CLS in a programme cleared all the text on screen when its line got hit.

This is the power of CLS. By removing all text from the screen, it gives your programmes a far tidier appearance.

The next command we need to have a look at is a command for pausing programmes while they are running.

TEMP=GET

The next new command that will help us build our personality test is TEMP=GET. Yes: TEMP followed by an equals sign followed by GET.

This command will pause the programme until the user presses any key. It's actually quite similar to INPUT, except it continues as soon as they press any key.

Try this. Start a NEW programme:

>NEW
>

And try these lines:

>10 PRINT "HELLO THERE! PRESS ANY KEY TO CONTINUE..."
>20 TEMP=GET
>30 PRINT "WELL DONE! YOU FOUND THE ANY KEY!"

RUN this programme and you will get:

>RUN
HELLO THERE! PRESS ANY KEY TO CONTINUE...

See how it is waiting on line 10, similar to what INPUT does?

So go ahead, press a key and you get the hilarious punchline:

>RUN
HELLO THERE! PRESS ANY KEY TO CONTINUE...
WELL DONE! YOU FOUND THE ANY KEY!

That's essentially what TEMP=GET is for, having this "PRESS ANY KEY TO CONTINUE" kind of functionality.

Learn, But Do Not Over-learn

That's great and all. But why exactly does this command consist of two words with an equals sign between them, when every other command we've learned in BASIC so far has been one word with no equals sign?

All will be revealed later. For now, just know that TEMP=GET is how you pause a programme until the user presses a key.

There's one more command we need to learn in order to make our personality test, and it's probably the most useful one yet...

AUTO

The final command we need to learn is AUTO. This is a command that saves you having to write the line numbers. This is very useful when creating big programmes like the one we plan on making (did I mention it's going to be biiiiiig!).

Give this a go, start a NEW programme again:

>NEW
>

Now type in AUTO and press ENTER:

>AUTO
   10

Ooh look at that! It's put a little "10" on there that we can type on top of!

Try this and hit ENTER:

>AUTO
   10 PRINT "HELLO"
   20

See what happened there? It's automatically made what you just typed line 10, and now moved on to line 20! So continue with this:

>AUTO
   10 PRINT "HELLO"
   20 PRINT "WOW CHECK OUT THESE LINE NUMBERS"
   30

Now it's put us onto 30! How good is that? It's like having a servant whose only job is to give you the next line number! Finish the programme with this:

>AUTO
   10 PRINT "HELLO"
   20 PRINT "WOW CHECK OUT THESE LINE NUMBERS"
   30 PRINT "LIFE IS GOOD!"
   40

We are done with the programme now, so we don't actually want to make a line 40. But we are still in AUTO mode! Are we trapped here forever? Do we have to continue writing lines of code until the end of time?

No, simple hit ESCAPE on your keyboard to come out of AUTO mode:

>AUTO
   10 PRINT "HELLO"
   20 PRINT "WOW CHECK OUT THESE LINE NUMBERS"
   30 PRINT "LIFE IS GOOD!"
   40
>

Now try RUNning the programme:

>AUTO
   10 PRINT "HELLO"
   20 PRINT "WOW CHECK OUT THESE LINE NUMBERS"
   30 PRINT "LIFE IS GOOD!"
   40
>RUN
HELLO
WOW CHECK OUT THESE LINE NUMBERS
LIFE IS GOOD!
>

And look at that! You just wrote a three line programme in record time, all because the AUTO command saved you having to put in the line numbers!

Boy, that sure will be useful when the amount of lines we'll be writing is much higher than three, because...

Judgemental Robot

Ok secret coder, you've come this far. You've learned about strings, integers, variables, random numbers, CLS, TEMP=GET and AUTO. Now it's time to put it all together to make something big and meaningful. I won't lie, this programme is long. But when you finish it, you'll be a different type of programmer to who you were when you started it.

Start off with a NEW programme again:

>NEW
>

Now go into AUTO mode:

>NEW
>AUTO
   10

And now, do this:

   10 CLS
   20 PRINT "HELLO, I AM THE JUDGEMENTAL ROBOT."
   30 PRINT "I AM HERE TO JUDGE YOU."
   40 PRINT "FIRSTLY, WHAT IS YOUR NAME?"
   50 INPUT NAME$
   60 CLS
   70 PRINT "HOW OLD ARE YOU, " + NAME$ + "?"
   80 INPUT AGE
   90 PRINT "GREAT"
   100 PRINT "SO " + NAME$ + "…"
   110 PRINT "THIS IS A FAMOUS PERSONALITY TEST."
   120 PRINT "I'M GOING TO ASK YOU SOME QUESTIONS."
   130 PRINT "ANSWER THEM HONESTLY, AND WRITE THE"
   140 PRINT "FIRST THING YOU THINK OF."
   150 PRINT "PRESS ANY KEY TO BEGIN."
   160 TEMP=GET
   170 CLS
   180 PRINT "PICTURE THE SCENE. "
   190 PRINT "YOU'RE WALKING THROUGH THE WOODS."
   200 PRINT "YOU'RE WITH SOMEONE. WHO IS IT?"
   210 INPUT FRIEND$
   220 CLS
   230 PRINT "AN ANIMAL APPEARS IN FRONT OF YOU."
   240 PRINT "WHAT KIND OF ANIMAL IS IT?"
   250 INPUT ANIMAL$
   260 CLS
   270 PRINT "YOU AND THE " + ANIMAL$ + " INTERACT."
   280 PRINT "WHAT ACTION TAKES PLACE?"
   290 INPUT ACTION$
   300 CLS
   310 PRINT "IN THE DISTANCE YOU CAN SEE A HOUSE."
   320 PRINT "DESCRIBE ITS SIZE?"
   330 INPUT HOUSE$
   340 CLS
   350 PRINT "IS THERE A FENCE AROUND THE HOUSE?"
   360 INPUT FENCE$
   370 CLS
   380 PRINT "YOU GO INTO THE HOUSE."
   390 PRINT "YOU FIND A DINING TABLE."
   400 PRINT "WHAT CAN YOU SEE ON THE TABLE?"
   410 INPUT TABLE$
   420 CLS
   430 PRINT "YOU EXIT THROUGH THE BACK DOOR."
   440 PRINT "IN THE GARDEN, LYING ON THE GRASS,"
   450 PRINT "THERE IS A CUP."
   460 PRINT "WHAT MATERIAL IS THE CUP MADE OF?"
   470 INPUT CUP$
   480 CLS
   490 PRINT "WHAT DO YOU DO WITH THE CUP?"
   500 INPUT DO$
   510 CLS
   520 PRINT "THANK YOU. THAT IS ALL QUESTIONS."
   530 PRINT "I WILL NOW JUDGE YOU."
   540 PRINT "PRESS ANY KEY TO HEAR MY JUDGEMENT"
   550 TEMP=GET
   560 CLS
   570 PRINT FRIEND$ + " IS THE MOST IMPORTANT PERSON IN YOUR LIFE."
   580 PRINT "(PRESS ANY KEY)"
   590 TEMP=GET
   600 CLS
   610 PRINT "THE SIZE OF THE ANIMAL IS HOW BIG YOU"
   620 PRINT "THINK YOUR CURRENT PROBLEMS ARE."
   630 PRINT "YOUR ANIMAL WAS: " + ANIMAL$
   640 PRINT "(PRESS ANY KEY)"
   650 TEMP=GET
   660 CLS
   670 PRINT "HOW YOU INTERACT WITH THE ANIMAL IS"
   680 PRINT "HOW PASSIVELY OR AGGRESIVELY YOU DEAL"
   690 PRINT "WITH YOUR PROBLEMS."
   700 PRINT "YOUR ACTION WAS: " + ACTION$
   710 PRINT "(PRESS ANY KEY)"
   720 TEMP=GET
   730 CLS
   740 PRINT "THE SIZE OF THE HOUSE IS THE SIZE OF"
   750 PRINT "YOUR AMBITION."
   760 PRINT "YOUR HOUSE SIZE WAS: " + HOUSE$
   770 PRINT "(PRESS ANY KEY)"
   780 TEMP=GET
   790 CLS
   800 PRINT "IF YOU HAD A FENCE AROUND THE HOUSE,"
   810 PRINT "YOU HAVE A CLOSED PERSONALITY -"
   820 PRINT "YOU DON'T LIKE PEOPLE DROPPING BY"
   830 PRINT "UNANNOUNCED."
   840 PRINT "IF YOU DIDN'T HAVE A FENCE, YOU HAVE"
   850 PRINT "AN OPEN PERSONALITY - PEOPLE ARE"
   860 PRINT "WELCOME AT ALL TIMES."
   870 PRINT "YOUR FENCE ANSWER WAS: " + FENCE$
   880 PRINT "(PRESS ANY KEY)"
   890 TEMP=GET
   900 CLS
   910 PRINT "IF YOU DIDN'T HAVE FOOD, FLOWERS OR"
   920 PRINT "TOYS ON THE TABLE, THEN YOU ARE"
   930 PRINT "GENERALLY UNHAPPY IN LIFE."
   940 PRINT "YOUR TABLE HAD: " + TABLE$
   950 PRINT "(PRESS ANY KEY)"
   960 TEMP=GET
   970 CLS
   980 PRINT "THE STRENGTH OF THE MATERIAL OF THE"
   990 PRINT "CUP IS HOW STRONG YOU THINK YOUR"
   1000 PRINT "RELATIONSHIP IS WITH " + FRIEND$
   1010 PRINT "YOUR CUP WAS MADE OF: " + CUP$
   1020 PRINT "(PRESS ANY KEY)"
   1030 TEMP=GET
   1040 CLS
   1050 PRINT "WHAT YOU DO WITH THE CUP SHOWS HOW YOU"
   1060 PRINT "FEEL ABOUT " + FRIEND$
   1070 PRINT "WITH THE CUP YOU: " + DO$
   1080 PRINT "(PRESS ANY KEY)"
   1090 TEMP=GET
   1100 CLS
   1110 PRINT "THANK YOU FOR TAKING THE FAMOUS"
   1120 PRINT "PERSONALITY TEST."
   1130 PRINT "I HAD FUN JUDGING YOU."
   1140 PRINT "I THINK WE BOTH LEARNED SOMETHING TODAY."
   1150 PRINT "NOW ASK A FRIEND TO TAKE THE TEST BY"
   1160 PRINT "RUNNING IT AGAIN."
   1170 PRINT "OH, AND ONE FINAL THING"
   1180 PRINT "YOUR LUCKY NUMBER IS:"
   1190 LUCKYMULT = RND(5) + 1
   1200 PRINT AGE * LUCKYMULT
   1210 PRINT "KEEP A LOOKOUT FOR THAT NUMBER"
   1220 PRINT "GOODBYE " + NAME$
   1230 PRINT ":)"
   1240

WOW did you get through all that? Now hit ESCAPE.

Trying running the programme to see if there's any mistakes.

Once any mistakes have been fixed, you should be able to do the quiz. You can even run the programme again and hand the computer to a friend or family member to give it a try. Make sure to tell them that it is your creation!

If you have got this far, then congratulations. I am well aware that this is a lot of code to write, for a language that is not in wide-spread use anymore. I made Secrets Of Coding because I wanted anybody who wanted to learn how to code to be able to without any barriers, as long as they were willing to put in the effort. If you have managed to get this far, then it means you are serious about learning how to code, and you probably do have the persistence to get there. I personally do not think anybody will get this far, so I stopped writing lessons here. Sadly I think it will always be the case that there will be a lot more money in writing code than in teaching it - I will probably never make back the money I spent on this project, and will be better off going back to my day job. But if you did finish that personality quiz, then I am telling you that you do have something special, and you can learn this even if it feels impossible right now. Please email me at jonathan.miles@hotmail.co.uk and I will genuinely try to help you get to the next stage of your learning.

And if this is the last we see of each other... than I hope you enjoyed the ride. Until next time, Secret Coder!