Java ans PDF

Title Java ans
Author crystal chen
Course Information Systems
Institution University of Auckland
Pages 15
File Size 386.4 KB
File Type PDF
Total Downloads 45
Total Views 169

Summary

Java ans...


Description

JavaScript 1 Answers

1. Intro to lessons 2-10 1.1. use alert to show a message alert('HelloMike,welcometoCodeAvengers') 1.2. run code that uses prompt to ask a question Click and answer the questions 1.3. use commands to move a robot robot.forward(5) 1.4. run an example project //Thiscodeaskstheuseraquestion

3.2. do addition and subtraction 7 2 7 3.3. do multiplication and division 32 16 2 3.4. do operations in the correct order 8 10 2 3.5. do operations in the correct order

varanswer=prompt('Whydoyouwanttolearntocode?\n1.To 1 buildcoolapps\n2.Getagreatjob\n3.Makelotsof 2 money\n4.Alloftheabove') 8 1.5. review quiz Review Quiz Questions: 1. 2. 3. 4.

alert * prompt bug

2. Display messages with [[alert]]

4. Basic math calculations 4.1. do a power calculation by multiplying alert(2*2*2*2*2*2*2*2*2*2) 4.2. do a decimal addition alert(16.7+16.7)

2.1. complete the alert message 4.3. use + to join text alert('Mostsoftwarerevenuein2011:MicrosoftUS$54.27 billion,IBMUS$22.49billion') 2.2. use \n to put text on a new line alert('Mostsoftwarerevenuein2011:\nMicrosoftUS$54.27 billion\nIBMUS$22.49billion') 2.3. add data on a new line in an alert message alert('Mostsoftwarerevenuein2011:\nMicrosoftUS$54.27 billion\nIBMUS$22.49billion\nOracleUS$20.96') 2.4. add another alert command alert('Mostsoftwarerevenuein2011:\nMicrosoftUS$54.27 billion\nIBMUS$22.49billion\nOracleUS$20.96') alert('Topwebsites:\nGoogle\nFacebook\nYouTube') 2.5. use "" instead of '' alert("Mostsoftwarerevenuein2011:\nMicrosoftUS$54.27 billion\nIBMUS$22.49billion\nOracleUS$20.96") alert("Topwebsites:\nGoogle\nFacebook\nYouTube")

alert('16.7'+16.7) 4.4. display the result of a calculation with an alert alert((16.7+16.7)/8*1000000000) 4.5. add text to explain the calculation alert('Googledonation$'+(16.7+16.7)/8*1000000000)

5. Store data with '''variables''' 5.1. display calculation results with an alert //showestimatedspreadofworm alert('Numberofinfectedcomputers'+  '\n20min:'+(160000*1.25)+  '\n40min:'+(160000*1.25*1.25)+  '\n60min:'+(160000*1.25*1.25*1.25) ) 5.2. update the calculation

3. Order of operation math rules 3.1. do a simple calculation alert(100‐27)

//showestimatedspreadofworm alert('Numberofinfectedcomputers'+  '\n20min:'+(240000*1.5)+  '\n40min:'+(240000*1.5*1.5)+  '\n60min:'+(240000*1.5*1.5*1.5) )

5.3. create a variable 7.1. move the robot forward varinitial=240000 varrate=1.5 //showestimatedspreadofworm alert('Numberofinfectedcomputers'+  '\n20min:'+(initial*rate)+  '\n40min:'+(initial*rate*rate)+  '\n60min:'+(initial*rate*rate*rate) ) 5.4. update the variables varinitial=280000 varrate=1.4 //showestimatedspreadofworm alert('Numberofinfectedcomputers'+  '\n20min:'+(initial*rate)+  '\n40min:'+(initial*rate*rate)+  '\n60min:'+(initial*rate*rate*rate) )

robot.forward(4) 7.2. turn the robot right robot.right() robot.forward(3) robot.right() robot.forward(2) robot.right() robot.forward(3) 7.3. turn the robot left robot.forward(3) robot.right() robot.forward(1) robot.left() robot.forward(3)

5.5. set variable values using other variables 7.4. turn the robot 180 degrees varinitial=280000 varrate=1.4 var_20min=initial*rate //showestimatedspreadofworm alert('Numberofinfectedcomputers'+  '\n20min:'+(_20min)+  '\n40min:'+(_20min*rate)+  '\n60min:'+(_20min*rate*rate) )

6. Read error messages, fix mistakes 6.1. fix bugs in an alert command alert('VIRUSALERT...Dr.Hackitisatitagain!') 6.2. fix bugs in alert commands

robot.right(2) robot.forward(3) robot.right() robot.forward(2) robot.right() robot.forward(3) robot.left() robot.forward(2) robot.left() robot.forward(3) 7.5. move the robot through a path robot.left() robot.forward(3) robot.left() robot.forward(8) robot.left() robot.forward(5)

alert('VIRUSALERT...Dr.Hackitisatitagain!') alert('AllS.C.R.I.P.T.agentsreporttoyourworkstations immediately!') 6.3. fix bugs in variable names varabbreviatedName='S.C.R.I.P.T.' varfullName='SpecializedCoderRecruitment&Internet ProtectionTaskforce'

8. Ask questions with [[prompt]] 8.1. create a prompt prompt('Whatisyourname?') prompt('Whatisyourage?') 8.2. add default answers to prompts

alert(abbreviatedName+','+fullName) 6.4. fix bugs in variable names

prompt('Whatisyourname?','Anonymous') prompt('Whatisyourage?','21') prompt('Whatisyourgender?','Male')

varabbreviatedName='S.C.R.I.P.T.' varfullName='SpecializedCoderRecruitment&Internet ProtectionTaskforce'

8.3. store user responses with variables

alert(abbreviatedName+','+fullName) varsecretCodeWord='Firewall' alert('The'+abbreviatedName+'secretwordis'+ secretCodeWord) 6.5. fix variable names and () varnoOfAgents=108 varnoOfManagers=32 varnoOfCleaners=20 varweeklyPay=(noOfAgents+noOfManagers)*78000/52+ (noOfCleaners*500) alert('TheaverageweeklypayatS.C.R.I.P.Tis$'+ weeklyPay/(noOfAgents+noOfManagers+noOfCleaners))

7. Move a robot to its goal

varname=prompt('Whatisyourname?','Anonymous') varage=prompt('Whatisyourage?','21') vargender=prompt('Whatisyourgender?','Male') 8.4. use the variable values varname=prompt('Whatisyourname?','Anonymous') varage=prompt('Whatisyourage?','21') vargender=prompt('Whatisyourgender?','Male')  alert('Thanksforyourtime'+name) 8.5. give some feedback varname=prompt('Whatisyourname?','Anonymous') varage=prompt('Whatisyourage?','21') vargender=prompt('Whatisyourgender?','Male') varfeedback=prompt('Entersomefeedbackplease:')  alert('Thanksforyourtime'+name)

9. Joining strings and numbers with {{+}}

10.5. changing variable values Review Quiz Questions:

9.1. use + to join strings a='CodeAvengers' b='abc' c='abc123' d='46' e='1234'

1. 15 2. 10 3. 5 4. 20

11. Intro to lessons 12-20

9.2. use + with numbers and strings

11.1. review \n

a='Dec2011' b='r2d2' c='2011' d='2000' e='2013'

alert('Keepitup!\n30lessonstogo...') 11.2. review prompt commands varname=prompt('Whatisyourname?','Anonymous') alert('Hello,'+name+',getreadyforlessons12‐20')

9.3. use * and / with strings 11.3. introduction to if statements a='32' b='64' c='50%' d='$48' e='32'

Click run, answer the question by typing spam, then click OK 11.4. detecting cancel Click run then click cancel. Click run again then click OK

9.4. practice using + to join strings a='1KB=1024B' b='75%' c='10GB=10240MB' d='450‐240=210' e='200KB(204800bytes)' 9.5. practice using + to join strings a='5678' b='8daysaweek' c='abceasyas123' d='99bottlesofmilkonthewall' e='24‐7‐365'

10. Review variable name rules 10.1. review variable creation Review Quiz Questions: 1. 2. 3. 4.

var ; var x = 5 var e = z

10.2. review variable name rules Review Quiz Questions: 1. 2. 3. 4.

$ _ full name birth month

10.3. review variable name rules Review Quiz Questions: 1. 2. 3. 4.

1stQuestion #2Q 100dollars fifty%

10.4. review math calculations Review Quiz Questions: 1. 2. 3. 4.

8 12 18 5

11.5. introduction to confirm Click run then click cancel. Click run again then click OK.

12. Check user responses with [[if statements]] 12.1. run an if statement Click run, type Firewall, then click OK 12.2. add another if statement varguess=prompt('WhatistheS.C.R.I.P.T.password?') //DisplayamessageIFtheguessiscorrect if(guess=='Firewall')  alert('Correct!')  if(guess=='SpamSniper') alert('Intruderalert!') 12.3. change to if–else if–else varguess=prompt('WhatistheS.C.R.I.P.T.password?') //DisplayamessageIFtheguessiscorrect if(guess=='Firewall')  alert('Correct!') elseif(guess=='SpamSniper') alert('Intruderalert!') else alert('Incorrect!') 12.4. if statements with multiple statements varguess=prompt('WhatistheS.C.R.I.P.T.password?') //DisplayamessageIFtheguessiscorrect if(guess=='Firewall'){  alert('Correct!') alert('WelcometoS.C.R.I.P.T.') }elseif(guess=='SpamSniper'){ alert('Intruderalert!') }else{ alert('Incorrect!') alert('Pleasetryagain') }

12.5. test all if statement branches

14.3. check the result with an if statement

varguess=prompt('WhatistheS.C.R.I.P.T.password?') //DisplayamessageIFtheguessiscorrect if(guess=='Firewall'){  alert('Correct!') alert('WelcometoS.C.R.I.P.T.') }elseif(guess=='Guest'){ alert('WelcometoS.C.R.I.P.T.') alert('Pleasewaitforyourhost') }elseif(guess=='SpamSniper'){ alert('Intruderalert!') }else{ alert('Incorrect!') alert('Pleasetryagain') }

varclickedOk=confirm('Areyousureyouwanttoleave?')  if(clickedOk==true){  alert('Goodbye') } 14.4. testing a confirm box varclickedOk=confirm('Areyousureyouwanttoleave?')  if(clickedOk==false){  alert('Thanksforstaying') } 14.5. add another confirm

13. true & false 13.1. greater > or less than < a=true b=false c=true d=false e=true f=true

varclickedOk=confirm('Areyousureyouwanttoleave?')  if(clickedOk==true){  clickedOk=confirm('Doyoureallywanttoleave?') }  if(clickedOk==false){  alert('Thanksforstaying') }else{  alert('Goodbye') }

13.2. using AND &&, OR || a=true b=false c=false d=true e=false f=true 13.3. using NOT ! a=false b=true c=false d=true e=true f=false 13.4. is equal to == a=false b=true c=true d=true e=true f=false 13.5. using < and > with strings a=false b=true c=false d=true e=false f=true

14. The [[confirm]] command 14.1. confirm box confirm('Areyousureyouwanttoleave?') 14.2. confirm box result varclickedOk=confirm('Areyousureyouwanttoleave?') alert(clickedOk)

15. [[if statement]] practice 15.1. == in if statement conditions Click run, type nothing in the prompt, then click OK. Click run again, type Male, then click OK. Click run again, type Female, then click OK. Click run once more, type boy, then click OK. 15.2. numbers in if statement conditions Click run, type nothing in the prompt, then click OK. Click run again, type 75, then click OK. Click run again, type 135, then click OK. Click run once more, type 75kg, then click OK 15.3. testing if statement conditions Click run, type nothing in the prompt, then click OK. Click run again, type 1.5 then click OK. Click run again, type 2.2, then click OK. Click run again, type 1.85, then click OK. Click run again, type 1.85m, then click OK 15.4. complex if statement conditions Run the code 6 times and do the following: 1. Put nothing in both prompts 2. Type Male for the gender prompt and 7 for the time prompt 3. Type Female then 16 4. Type Male then 15 5. Type Female then type 19 6. Type boy then 20mins 15.5. complex if statement conditions Click run, type 61 and 0, then click OK. Click run again, type 0 and 121, then click OK. Click run again, type 50 and 100, then click OK. Click run once more, type 10 and 10, then click OK

16. Move 2 robots to their goal 16.1. move the robots to the X robot.forward(4) 16.2. move the robots to the X robot.forward(5) robot.right() robot.forward(1)

16.3. move the robots to the X

17.4. if statement practice

robot.forward(4) robot.right() robot.forward(1)

varnativeLanguage=prompt('Whatisyournativelanguage?', 'English')  if(nativeLanguage=='Spanish'){  alert('Graciasportutiempo') }elseif(nativeLanguage=='French'){  alert('Mercipourvotretemps') }elseif(nativeLanguage!=null){  alert('Thanksforyourtime') }

if(!robot.onX()){  robot.right(2)  robot.forward(1) } 16.4. move the robots to the X robot.forward(4) robot.right() if(robot.atWall()){  robot.right(2) } robot.forward(1) 16.5. move the robots to the X robot.forward(1) if(robot.atWall()){  robot.right()  robot.forward(8)  robot.right()  robot.forward(1) }else{  robot.forward(7)  robot.right()  robot.forward(2)  robot.right()  robot.forward(8) }

17. The special value '''null''' 17.1. prompt box cancel button varnativeLanguage=prompt('Whatisyournativelanguage?', 'English') alert(nativeLanguage) 17.2. null value varnativeLanguage=prompt('Whatisyournativelanguage?', 'English') if(nativeLanguage==null){  nativeLanguage=prompt('Whatisyournative language?','English') } 17.3. check for cancel varnativeLanguage=prompt('Whatisyournativelanguage?', 'English') if(nativeLanguage==null){  nativeLanguage=prompt('Whatisyournative language?','English') } if(nativeLanguage!=null){ alert('Thanksforyourtime') }

17.5. using OR || in if statement conditions varnativeLanguage=prompt('Whatisyournativelanguage?', 'English')  if(nativeLanguage=='Spanish'||nativeLanguage== 'español'){  alert('Graciasportutiempo') }elseif(nativeLanguage=='French'||nativeLanguage== 'français'){  alert('Mercipourvotretemps') }elseif(nativeLanguage!=null){  alert('Thanksforyourtime') }

18. Read error messages, fix mistakes 18.1. review if statement mistakes varguess=prompt('WhatistheS.C.R.I.P.T.password?')  if(guess=='Firewall')  alert('Correct!') else  alert('Incorrect!') 18.2. review if statement mistakes varguess=prompt('WhatistheS.C.R.I.P.T.password?')  if(guess=='Firewall')  alert('Correct!') elseif(guess=='Guest')  alert('WelcometoS.C.R.I.P.T.') else  alert('Incorrect!') 18.3. review if statement mistakes varguess=prompt('WhatistheS.C.R.I.P.T.password?')  if(guess=='Firewall')  alert('Correct!') elseif(guess=='SpamSniper')  alert('Intruderalert!') elseif(guess=='Guest')  alert('WelcometoS.C.R.I.P.T.') else  alert('Incorrect!') 18.4. review if statement mistakes varguess=prompt('WhatistheS.C.R.I.P.T.password?')  if(guess=='Firewall'){  alert('Correct!')  alert('WelcometoS.C.R.I.P.T.') }elseif(guess=='SpamSniper'){  alert('Intruderalert!')  alert('Robotdispatched') }elseif(guess=='Guest'){  alert('WelcometoS.C.R.I.P.T.')  alert('Pleasewaitforyourhost') }else{  alert('Incorrect!')  alert('Pleasetryagain') }

18.5. review if statement mistakes

19.5. improve code layout

varguess=prompt('WhatistheS.C.R.I.P.T.password?')

alert('WelcometotheS.C.R.I.P.T.jobrecruitmentsite')  varage=prompt('Whatisyourage?')  if(age=80){ alert('Sorryyouaretooold') }elseif(age>=22&&age1&&age...


Similar Free PDFs