JavaScript 1 Answers 1. Intro To Lessons 2-10

3y ago
485 Views
130 Downloads
223.34 KB
15 Pages
Last View : 21d ago
Last Download : 3m ago
Upload by : Callan Shouse
Transcription

JavaScript 1 Answers1. Intro to lessons 2-101.1. use alert to show a messagealert('Hello Mike, welcome to Code Avengers')1.2. run code that uses prompt to ask a questionClick and answer the questions1.3. use commands to move a robotrobot.forward(5)1.4. run an example project//This code asks the user a questionvar answer prompt('Why do you want to learn to code?\n1. Tobuild cool apps\n2. Get a great job\n3. Make lots ofmoney\n4. All of the above')3.2. do addition and subtraction7273.3. do multiplication and division321623.4. do operations in the correct order81023.5. do operations in the correct order1281.5. review quizReview Quiz Questions:1.2.3.4.alert*promptbug2. Display messages with [[alert]]4. Basic math calculations4.1. do a power calculation by multiplyingalert(2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2)4.2. do a decimal additionalert(16.7 16.7)2.1. complete the alert messagealert('Most software revenue in 2011: Microsoft US 54.27billion, IBM US 22.49 billion')4.3. use to join textalert('16.7' 16.7)2.2. use \n to put text on a new line4.4. display the result of a calculation with an alertalert('Most software revenue in 2011:\nMicrosoft US 54.27billion\nIBM US 22.49 billion')alert((16.7 16.7) / 8 * 1000000000)2.3. add data on a new line in an alert messagealert('Most software revenue in 2011:\nMicrosoft US 54.27billion\nIBM US 22.49 billion\nOracle US 20.96')2.4. add another alert commandalert('Most software revenue in 2011:\nMicrosoft US 54.27billion\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.27billion\nIBM US 22.49 billion\nOracle US 20.96")alert("Top websites:\nGoogle\nFacebook\nYouTube")3. Order of operation math rules3.1. do a simple calculationalert(100 ‐ 27)4.5. add text to explain the calculationalert('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 wormalert('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//show estimated spread of wormalert('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 variable7.1. move the robot forwardvar initial 240000var rate 1.5//show estimated spread of wormalert('Number of infected computers' '\n20min: ' (initial * rate) '\n40min: ' (initial * rate * rate) '\n60min: ' (initial * rate * rate * rate))robot.forward(4)7.2. turn the robot ot.forward(2)robot.right()robot.forward(3)5.4. update the variablesvar initial 280000var rate 1.4//show estimated spread of wormalert('Number of infected computers' '\n20min: ' (initial * rate) '\n40min: ' (initial * rate * rate) '\n60min: ' (initial * rate * rate * rate))7.3. turn the robot obot.left()robot.forward(3)5.5. set variable values using other variables7.4. turn the robot 180 degreesvar initial 280000var rate 1.4var 20min initial * rate//show estimated spread of wormalert('Number of infected computers' '\n20min: ' ( 20min) '\n40min: ' ( 20min * rate) '\n60min: ' ( 20min * rate * 6. Read error messages, fix mistakes7.5. move the robot through a path6.1. fix bugs in an alert RUS ALERT. Dr.Hackit is at it again!')6.2. fix bugs in alert commandsalert('VIRUS ALERT. Dr.Hackit is at it again!')alert('All S.C.R.I.P.T. agents report to your workstationsimmediately!')8. Ask questions with [[prompt]]8.1. create a prompt6.3. fix bugs in variable namesprompt('What is your name?')prompt('What is your age?')var abbreviatedName 'S.C.R.I.P.T.'var fullName 'Specialized Coder Recruitment & InternetProtection Taskforce'8.2. add default answers to promptsalert(abbreviatedName ', ' fullName)6.4. fix bugs in variable namesprompt('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 & InternetProtection Taskforce'8.3. store user responses with variablesvar name prompt('What is your name?', 'Anonymous')var age prompt('What is your age?', '21')var gender prompt('What is your gender?', 'Male')alert(abbreviatedName ', ' fullName)var secretCodeWord 'Firewall'alert('The ' abbreviatedName ' secret word is ' secretCodeWord)8.4. use the variable values6.5. fix variable names and ( )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 noOfAgents 108var noOfManagers 32var noOfCleaners 20var 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 goalalert('Thanks for your time ' name) 8.5. give some feedbackvarvarvarvarname prompt('What is your name?', 'Anonymous')age prompt('What is your age?', '21')gender prompt('What is your gender?', 'Male')feedback prompt('Enter some feedback please:')alert('Thanks for your time ' name)

9. Joining strings and numbers with {{ }}9.1. use to join stringsabcde 'Code Avengers''abc''abc 123''46''1234'10.5. changing variable valuesReview Quiz Questions:1. 152. 103. 54. 2011. Intro to lessons 12-209.2. use with numbers and strings11.1. review \nabcdealert('Keep it up!\n30 lessons to go.') 'Dec 2011''r2d2''2011''2000''2013'9.3. use * and / with stringsabcde '32''64''50%'' 48''32'11.2. review prompt commandsvar name prompt('What is your name?', 'Anonymous')alert('Hello, ' name ', get ready for lessons 12‐20')11.3. introduction to if statementsClick run, answer the question by typing spam, then click OK11.4. detecting cancelClick run then click cancel. Click run again then click OK9.4. practice using to join stringsabcde '1KB 1024B''75%''10GB 10240MB''450 ‐ 240 210''200KB (204800 bytes)'9.5. practice using to join stringsabcde '5678''8 days a week''abc easy as 123''99 bottles of milk on the wall''24‐7‐365'10. Review variable name rules10.1. review variable creationReview Quiz Questions:1.2.3.4.var;var x 5var e z10.2. review variable name rulesReview Quiz Questions:1.2.3.4. full namebirth month10.3. review variable name rulesReview Quiz .4. review math calculationsReview Quiz Questions:1.2.3.4.81218511.5. introduction to confirmClick run then click cancel. Click run again then click OK.12. Check user responses with [[if statements]]12.1. run an if statementClick run, type Firewall, then click OK12.2. add another if statementvar guess prompt('What is the S.C.R.I.P.T. password?')//Display a message IF the guess is correctif (guess 'Firewall')alert('Correct!')if (guess 'SpamSniper')alert('Intruder alert!')12.3. change to if–else if–elsevar guess prompt('What is the S.C.R.I.P.T. password?')//Display a message IF the guess is correctif (guess 'Firewall')alert('Correct!')else if (guess 'SpamSniper')alert('Intruder alert!')elsealert('Incorrect!')12.4. if statements with multiple statementsvar guess prompt('What is the S.C.R.I.P.T. password?')//Display a message IF the guess is correctif (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 branches14.3. check the result with an if statementvar guess prompt('What is the S.C.R.I.P.T. password?')//Display a message IF the guess is correctif (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 boxvar clickedOk confirm('Are you sure you want to leave?')if (clickedOk false) {alert('Thanks for staying')}14.5. add another confirm13. true & false13.1. greater or less than abcdef truefalsetruefalsetruetruevar 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 abcdef truefalsefalsetruefalsetrue13.3. using NOT !abcdef falsetruefalsetruetruefalse13.4. is equal to abcdef falsetruetruetruetruefalse13.5. using and with stringsabcdef falsetruefalsetruefalsetrue14. The [[confirm]] command14.1. confirm boxconfirm('Are you sure you want to leave?')14.2. confirm box resultvar clickedOk confirm('Are you sure you want to leave?')alert(clickedOk)15. [[if statement]] practice15.1. in if statement conditionsClick run, type nothing in the prompt, then click OK. Click run again, typeMale, then click OK. Click run again, type Female, then click OK. Click runonce more, type boy, then click OK.15.2. numbers in if statement conditionsClick 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 OK15.3. testing if statement conditionsClick 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, type1.85, then click OK. Click run again, type 1.85m, then click OK15.4. complex if statement conditionsRun the code 6 times and do the following:1. Put nothing in both prompts2. Type Male for the gender prompt and 7 for the time prompt3. Type Female then 164. Type Male then 155. Type Female then type 196. Type boy then 20mins15.5. complex if statement conditionsClick run, type 61 and 0, then click OK. Click run again, type 0 and 121, thenclick OK. Click run again, type 50 and 100, then click OK. Click run oncemore, type 10 and 10, then click OK16. Move 2 robots to their goal16.1. move the robots to the Xrobot.forward(4)16.2. move the robots to the Xrobot.forward(5)robot.right()robot.forward(1)

16.3. move the robots to the X17.4. if statement (1)var nativeLanguage prompt('What is your native language?','English')if (!robot.onX()) {robot.right(2)robot.forward(1)}16.4. move the robots to the Xrobot.forward(4)robot.right()if (robot.atWall()) {robot.right(2)}robot.forward(1)16.5. move the robots to the Xrobot.forward(1)if (robot.atWall()) orward(1)} else t.right()robot.forward(8)}17. The special value '''null'''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')}17.5. using OR in if statement conditionsvar 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 mistakes18.1. review if statement mistakesvar guess prompt('What is the S.C.R.I.P.T. password?')if (guess )18.2. review if statement mistakes17.1. prompt box cancel buttonvar guess prompt('What is the S.C.R.I.P.T. password?')var nativeLanguage prompt('What is your native language?','English')alert(nativeLanguage)if (guess 'Firewall')alert('Correct!')else if (guess 'Guest')alert('Welcome to S.C.R.I.P.T.')elsealert ('Incorrect!')17.2. null valuevar nativeLanguage prompt('What is your native language?','English')if (nativeLanguage null) {nativeLanguage prompt('What is your nativelanguage?', 'English')}17.3. check for cancelvar nativeLanguage prompt('What is your native language?','English')if (nativeLanguage null) {nativeLanguage prompt('What is your nativelanguage?', 'English')}if (nativeLanguage ! null) {alert('Thanks for your time')}18.3. review if statement mistakesvar 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.')elsealert ('Incorrect!')18.4. review if statement mistakesvar 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 mistakes19.5. improve code layoutvar 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')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')}var age prompt('What is your age?')if (age 18) {alert('Sorry you are too young')} else if (age 80) {alert('Sorry you are too old')} else if (age 22 && age 28) {alert('Apply for a Special Agent job')} else {alert('Apply for an office or cleaning job')}20. Review terminology19. Combining conditions with {{&&}} and {{ }}19.1. re-ask a question if the user clicks cancelvar age prompt('What is your age?')if (age null) {age prompt('Please type your age')}19.2. check the user types a valid agevar age prompt('What is your age?')if (age null) {age prompt('Please type your age')}if (age 1 && age 115) {alert('Thank you')} else {alert('Invalid age')}19.3. check the code and fix the mistakealert('Welcome to the S.C.R.I.P.T. job recruitment site')var age prompt('What is your age?')if (age 18) {alert('Sorry you are too young')}19.4. complete if conditionsalert('Welcome to the S.C.R.I.P.T. job recruitment site')var age prompt('What is your age?')if (age 18) {alert('Sorry you are too young')} else if (age 80) {alert('Sorry you are too old')} else if (age 22 && age 28) {alert('Apply for a Special Agent job')} else {alert('Apply for an office or cleaning job')}20.1. review if statementsReview Quiz Questions:1. (2. else3. 4. { }20.2. match the definitions with the termsReview Quiz Questions:1. Boolean2. String3. Function4. Variable20.3. review variable name rulesReview Quiz Questions:1. if2. true3. false4. var20.4. review alert, prompt, and confirm boxesReview Quiz Questions:1. null2. null3. false4. 120.5. review some special symbolsReview Quiz Questions:1. 2.3. &&4. !21. Intro to lessons 22-3021.1. review if statementsClick run then type Male or Female. Make sure the 1st letter is a capital.21.2. review logicClick run, type 1.8, then click OK21.3. review confirmClick run, then click OK three times21.4. introduction to while loopClick run, then click Cancel twice, then type your name and click OK21.5. introduction to while loopClick run, type 25 and click OK, then repeat three more times.

22. Repeat code with [[while]] loops22.1. ask questions and display responsesvar response prompt('Why are you learning JavaScript?');alert('Thanks for learning.');22.2. re-ask questions if the user clicks cancelvar response prompt('Why are you learning JavaScript?');if (response null) {response prompt('Why are you learning JavaScript?');}alert('Thanks for learning.');22.3. use a while loop to force the user to answer a questionvar response prompt('Why are you learning JavaScript?');while (response null) {response prompt('Why are you learning JavaScript?');}alert('Thanks for learning.');22.4. re-ask a question if the user clicks OK without typing anythingvar response prompt('Why are you learning JavaScript?');while (response null response '') {response prompt('Why are you learning JavaScript?');}23.4. loop a set number of timesvar number 5;var text number;while (number 35) {number number 5;text text ', ' number;}console.log(text);23.5. loop a set number of timesvar number 90;var text number;while (number 300) {number number 3;text text ', ' number;}console.log(text);24. [[While]] loops quiz24.1. understand while loopsa 3b 624.2. understand while loopsa 3b 4alert('Thanks for learning.');24.3. understand while loops22.5. test on valid and invalid inputsvar response prompt('Why are you learning JavaScript?');while (response null response '') {response prompt('Why are you learning JavaScript?');}alert('Thanks for learning.');a 5b 1024.4. understand while loopsa 12b ‐524.5. understand while loops23. Loop a set number of timesa ‐4b ‐1023.1. loop a set number of timesvar number 1;while (number 10) {console.log(number);number number 1;}23.2. loop a set number of timesvar number 1;while (number 11) {console.log(number);number number 2;}23.3. loop a set number of timesvar number 5;while (number 35) {console.log(number);number number 5;}25. Fix [[infinite loops]]25.1. fix an infinite loopvar n 1;while (n 5) {console.log(n);n n 1;}25.2. fix an infinite loopvar n 0;while (n 15) {n n 3;console.log(n);}n 0;while (n 20) {n n 4;console.log(n);}

25.3. fix an infinite loop26.4. move each robot to the Xvar n 5;while (robot.atWall() false) {robot.forward();}while (n 0) {n n ‐ 1;console.log(n);}while (n 4) {n n 1;console.log(n);}25.4. fix loop bugsrobot.right();robot.forward();26.5. complete the code to move each robot to the Xwhile ( robot.atWall() false ) {robot.forward();}robot.left();var name prompt('What is your name?');while (name null name '') {name prompt('Please enter your name');}alert('Hello ' name);25.5. fix an infinite loopvar n 0;while (n ! 15) {n n 3;console.log(n);}n 0;while (n ! 20) {n n 4;console.log(n);}26. Simplify code with [[while]] loops26.1. use a loop to move the robot to the Xvar n 0;while (n 6) {n n 1;robot.forward();}if ( robot.atWall() true ) {robot.right();robot.right();}while ( robot.atWall() false ) {robot.forward();}robot.left();if ( robot.atWall() true ) {robot.right();robot.right();}while ( robot.atWall() false ) {robot.forward();}27. [[While]] loop conditions27.1. step through while loop codea 11b 827.2. step through while loop codea 64b 5527.3. step through while loop code26.2. extend the code to move the robot to the Xvar n 0;while (n 6) {n n 1;robot.forward();}robot.right();while (n 8) {n n 1;robot.forward();}a 5b 427.4. step through while loop codea 3b 327.5. step through while loop codea 2b 5robot.right();while (n 11) {n n 1;robot.forward();}26.3. move each robot to the Xwhile ( robot.onX() false ) {robot.forward();}28. Weekly wage calculator28.1. create a loop that repeats 5 timesvar dayNo 1;while (dayNo 5) {alert(dayNo);dayNo day

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

Related Documents:

JavaScript Manual for LCCS Teachers 13 Client-side JavaScript vs. server-side JavaScript For many years JavaScript was a client-side scripting language. This was because JavaScript programs could only be run from inside web browsers which were installed on client machines. Because of the fact that JavaScript code can run on client devices it means

- The Spark web app framework . Yahoo JavaScript PHP Amazon.com JavaScript Java, C , Perl Wikipedia.org JavaScript PHP, Hack Twitter.com JavaScript C , Java, Scala, Ruby Bing JavaScript ASP.net eBay.com JavaScript Java, JavaScript, Scala . Note the MVC architecture

JavaScript. Check a framework's documentation for details. Using the SDK with Web Browsers All major web browsers support execution of JavaScript. JavaScript code that is running in a web browser is often called client-side JavaScript. Using the SDK for JavaScript in a web browser differs from the way in which you use it for Node.js. The

Praise for Effective JavaScript "Living up to the expectation of an Effective Software Development Series pro-gramming book, Effective JavaScript by Dave Herman is a must-read for anyone who wants to do serious JavaScript programming. The book provides detailed explanations of the inner workings of JavaScript, which helps readers take better

JavaScript directly within the HTML file. We can also include more than one script tag and can include a mix of internal JavaScript and external JavaScript files. This will be useful, for example, if we have some JavaScript that is appropriate for many of our webpages and then some JavaScript that is specific to one page. Function Definition

answers, realidades 2 capitulo 2a answers, realidades 2 capitulo 3b answers, realidades 1 capitulo 3a answers, realidades 1 capitulo 5a answers, realidades 1 capitulo 2b answers, realidades 2 capitulo 5a answers, realidades capitulo 2a answers, . Examen Del Capitulo 6B Answers Realidades 2 Realidades 2 5a Test Answers Ebook - SPANISH .

JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages JavaScript can put dynamic text into an HTML page - A JavaScript statement like this:

AWS SDK for JavaScript Developer Guide for SDK Version 3 Maintenance and support for SDK major versions What is the AWS SDK for JavaScript? Welcome to the AWS SDK for JavaScript Developer Guide. This guide provides general information about setting up and configuring the AWS SDK for JavaScript. It also walks you through examples and tutorial