A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011 · Edited for Alice 3 use...
Transcript of A Simple Quiz for Alice 3.2: Step 1: Create the Quiz ... · 7/2/2011 · Edited for Alice 3 use...
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
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.
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...
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...
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.
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