A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use...

6
A Simple Quiz for Alice 3.2: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011, Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will demonstrate how to create a simple quiz using the three different kinds of “ask user” functions: ask user for a number, ask user for true or false and ask user for a string. Open a new Alice grass world. Click on Setup Scene. Choose Browse Gallery By Group, and click Animals. Add one Penguin, one Cow , and three Chickens into your world. Arrange and resize the objects so they are easy to see. Click Edit Code when finished. Let's get started by setting up the world. Create a new scene procedure that we will use later to hold the instructions for the quiz. Step 1: Create the Quiz Procedure Lets start by creating a quiz procedure Click on the Scene tab and choose Add Scene Procedure Name the new procedure: quiz. Click back on myFirstMethod. Now we will add the quiz to MyFirstMethod. Make sure you are in MyFirstMethod. Click on this.penguin in the object tree. Drag the say procedure into the procedure editor and type in: Time for a quiz. Drag in a second say procedure and type in: That is all folks! Click on this in the object tree and drag the quiz procedure in between the two penguin say commands Step 2: Set Up MyFirstMethod

Transcript of A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use...

Page 1: A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will

ASimpleQuizforAlice3.2:AskUserFunctions.

ByLanaDyck

underthedirectionofProfessorSusanRodger

DukeUniversity

June2009,addedPart2July2011,

EditedforAlice3useandPart3,4addedbyAnhTrinhJuly2016

Introduction and Set-up

Thistutorialwilldemonstratehowtocreateasimplequizusingthethreedifferentkindsof“askuser”functions:askuserforanumber,askuserfortrueorfalseandaskuserforastring.

OpenanewAlicegrassworld.

ClickonSetupScene.

ChooseBrowseGalleryByGroup,and

clickAnimals.

AddonePenguin,oneCow,andthree

Chickens intoyourworld.

Arrangeandresizetheobjectsso

theyareeasytosee.

ClickEditCodewhenfinished.

Let'sgetstartedbysettinguptheworld.

Createanewsceneprocedurethatwewilluselatertoholdtheinstructionsforthequiz.

Step 1: Create the Quiz Procedure

Letsstartbycreatingaquiz

procedure

ClickontheScene taband

chooseAddSceneProcedure

Namethenewprocedure:quiz.

ClickbackonmyFirstMethod.

Nowwewilladdthequizto

MyFirstMethod.

MakesureyouareinMyFirstMethod.

Clickonthis.penguin intheobjecttree.

Dragthesay procedureintothe

procedureeditorandtypein:

Timeforaquiz.

Draginasecondsay procedureand

typein:Thatisallfolks!

Clickonthis intheobjecttreeanddrag

thequiz procedureinbetweenthetwo

penguinsaycommands

Step 2: Set Up MyFirstMethod

Page 2: A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will

Nowwewillstartwritingthequizprocedure.Tomakeourcodeeasiertoread

wewilladdincomments.Commentsmakeitpossibletoaddinnotesaboutthe

codelike,whatitwilldo,orwhowrotethecode.

Firstclickonthequizproceduretab.

Toaddacommentdraganddropthedoubleslashbuttonintothe

method

Step 3: Comments

Typeinthecommenteditor:Question1

Clickonthis.penguin intheobjecttree,haveitsay:Howmanyanimalsintheworld?andsetthedurationto2seconds.

Step 4: Question #1

Weneedavariabletostore

thenumberinformation

wegetfromtheuser.

Draginthe

buttontoopenvariable

optionbox.

NameitanswerNumber.SelectWholeNumber

besidevaluetype,initialize

itto0andclickOK.

Clickontheworld intheobjecttree.

Undertheworld'sdetails,functions find“askuserforanumber.”

Clickanddragtheaskuserforanumber overthe1andselectother...

Enterthestring:Enterthenumberofanimals:

Step 4: Question #1Continued...

Nowwewilldeterminewhathappensiftheanswergiveniscorrectorincorrect.

DraganddropanIf blockfromthebottomofthewindowandsetittotrue.

Step 4: Question #1Continued...

ChooseRelational(WholeNumber)in

thetruedrop-downlist.

Select“???==???“->answerNumber...

->CustomWholeNumbertoenterin

thevalue5.5isthecorrectanswertothisquestion.

Page 3: A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will

Forthisquestionwhenthe“If”statementistrue,theansweriscorrect.Sowewill

putourresponsetothecorrectanswerfirst.

Clickonthis.penguin intheobjecttree.

UndertheIf:

Dragthesay methodandtype:CorrectDragtheturn methodandselect1

Whentheifstatementisfalse,theanswerisincorrect.

UndertheElse:

Dragthesay methodandtype:Sorry,thatisnotcorrect.

Step 4: Question #1Continued...

Runyourworldtotakethe

onequestionquiz.

Nowletsmakeaquestionthataskstheuserforatrueorfalseresponse.

Dropinacommentandtypein:Question2Clickonpenguin intheobjecttree,haveitsay:Aretheremorechickensthanpenguins?andsetthedurationto2seconds.

Step 5: Question #2

Weneedavariabletostoretheboolean

informationwegetfromtheuser.

Draginvariable buttonfromthebottomof

thewindow.

NameitanswerBoolean.

SelectBooleanandClickOK.

Inthepenguin'sfunctions,draganddropthe“getBooleanFromUser”

overthetrue.

Typein:Clickontrueandfalse.

Step 5: Question #2Continued...

NowwewilladdinourresponsestotheanswerinanotherIf/Elsestatement.

DraganddropanIf/Else

statementandselectanswerBoolean.

TheIfquestionacceptsjustthevariablebecauseanswerBooleanisaboolean

type.

Step 5: Question #2Continued...

Page 4: A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will

Nowcompletethequestion#2byaddinginthe

proceduresasshownbelow:

Step 5: Question #2Continued...

Runyourworldtotake

thetwoquestionquiz.

Forourfinalquestionwewillasktheusertoenterastring.

Dropinacommentandtypein:Question3

Clickonpenguin intheobjecttree,haveit

say:Whatbuildingarewein?andsetthedurationto2seconds.

Step 6: Question #3

Weneedavariabletostorethestringinformationwegetfromtheuser.

Draginthevariable button.

NameitanswerString.

SelectTextStringand‘hello’ininitializer

ClickOK.

Note: Astringisasetof

lettersorcharacters.Aspaceis

consideredacharactersobe

carefulifyouhaveaspaceat

theendofyourwordor

sentence.

Inthepenguin'sfunctions,

draganddropthegetStringFromUser overthe‘hello’string.

Typein:Enteracronym.

Step 6: Question #3Continued...

NowwewilladdinourresponsestotheanswerinanotherIf/Elsestatement.

DraganddropanIf/Else statementandselecttrue.

ClickthedownarrowintrueandselectTextStringComparison->

???equalsIgnoreCase???-> answerString-> CustomTextString thentypein:LSRC

WithequalsIgnoreCase,theanswerisnotcase-sensitive

Step 6: Question #3Continued...

Page 5: A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will

Clickonpenguinintheobjecttreeandaddintheresponses

forwhentheansweriscorrectorincorrectasshownbelow.

Nowplayyourworldandtakethequiz.

Step 6: Question #3Continued...

Part 2: Forcing the Answer

InQuestion1,iftheusermistypestheanswer,wewantthe

programtoasktheuserfortheansweragainuntilitiscorrect.

Rewritequestion1toaddawhileloopandforcetheuserintothe

loopwithawrongvaluetostartwith.

Part 3: Limiting Number of Trials

Tolimitthenumberoftrialsto3forexample,createanewvariablenamed

numberofTrial,createawhileloopthatallowsthequestiontoshowupaslongas

thestudentstrieslessthan3times.Eachtimetheyanswerincorrectly,increment

numberofTrial by1.Iftheyanswer,correctly,setnumberofTrial toanumbergreater

than3tobreakoutofthewhileloop(herewechoose5)

Part 4: Score Reporting

Challenge:Toreportscoretouser,wehavetocreatealocalvariablescore forthe

quizprocedure,initializeitto0,andincrementitby1everytimethestudent

answeraquestioncorrectly.Attheend,havethepenguinreportthescore.

Page 6: A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011  · Edited for Alice 3 use and Part 3,4 added by Anh Trinh July 2016 Introduction and Set-up This tutorial will

Toreportthescoreintheend,dragthepenguinsayprocedureinandtype

“Yougot”.

Clickonthedownarrownexttothestringyoujusttypedandselect“Yougot

“+???->WholeNumber->score

Part 4: Score Reporting

Clickonthedownarrownexttothe“Yougot“+scorestringandselect“You

got“+score+??? ->CustomTextString andType”questionscorrect”

Part 4: Score Reporting

Quiz Procedure code