Conditionals & Input

 Zoom Name:


Video Introduction (4 minutes) <<--- Watch this video first, then

English IDE <<--- Click this link and rewrite (improve) your first program here.

When it runs correctly (without errors or warnings) click the yellow Done button.
Then come back here and click this Next link to skip down to the next video.

If it's not a link yet, you might need to refresh your browser, or else click this button to call a mentor:

If you are like me and prefer to read at your own pace instead of whatever pace set in some video, You can read the transcript (and probably come out ahead of the non-readers).

Video Transcript: 2. Conditionals & Input

I'm assuming you ran your first English program, maybe it looks something like this, with jam on your sandwich.
"get ingredients"
    open cabinet
    get jam
    get PB
    get bread
    done

"get stuff"
    get ingredients
    get tools
    done

"get tools"
    open cabinet
    open drawer
    get knife
    get plate
    done

"put it together"
    Open PB
    Open bread.
    Open jam.
    Get piece of bread.
    Get piece of bread.
    get jam on knife
    Spread jam on bread.
    get pb on knife
    Spread PB on bread.
    Put bread pieces together.
    done

"make PBJ"
    get stuff
    put it together
    done
 


It's a start. But the real world is not a straight line like this program. We have turns and switches, conditions and curlicues.

Things Happen, and we need to deal with it. Maybe you ran out of grape jelly, so you must make your sandwich from strawberry. Or maybe grape is boring, let's try peach today. You can do that: "I feel like strawberry today," and you alone know how you feel.

So let's pretend we are making this sandwich for your finicky brother or cousin or whatever, and he's on a rigid schedule: Monday it's grape, Tuesday it's peach, Wednesday it's strawberry.

On the third line of my program, where it says

get jam
Change that one line to these two lines:
if it is Monday get grape
any other day get strawberry
Do you see the calendar near the left edge of the Kitchen computer? What day is it when you run this revised program? Did it choose the right jam?

How would you know if the other line worked correctly? I guess you could wait until that day of the week rolled around, then run it again, but there's an easier cheat: Insert at the beginning of the main program, before the line where it calls the subroutine "get stuff" but inside the "make PBJ" subroutine

it is Tuesday
(or whatever day it isn't), then try it again. Did you see the day change on the calendar? You can also change the month, like
it is December
or the time on the wall clock over the fridge:
it is 11:30
But testing the exact time is difficult, it might be better to try for before or after a particular time.

Anyway, your finicky cousin didn't get his peach jam on Tuesday. You can fix that. Then click the Done button. If you get stuck, that's what the Mentors are for (click this button to get help)

Congratulations! Your program ran correctly. Click this link to advance to the next segment: Iteration
 

Bonus

The Kitchen computer can do up to four jars in one program. One of them is peanut butter, but if you want a fourth color of jam, you could do a sandwich with two jams and no PB. There are only four flavors of jam it knows about: Strawberry (the default, if you don't specify some other), peach, marmalade, and grape jelly ("jelly" by itself is the same as grape). Or if you like weird taste, there's a jar of mayonaise in the fridge -- it's one of the four jars, and it disappears if you need it for jam 

There's some butter in the fridge too, but I ran out of time before I could tell the computer how to get butter on the knife so it can spread it on your bread. Yes, everything the computer knows how to do, somebody (in this case, me) told it how to do that. All that animation, it's (Java) code in the Game Engine, which you will learn how to do yourself later in this course. The mayo was for when I add deli meats for a ham&swiss sandwich, but like I said, I ran out of time. Programming is like that. Maybe next year (if you come back). But the cereal in a bowl with milk works. You can even eat it. Try it. Start simple and see what is assumed.

[2022 September 28]