Presentation is loading. Please wait.

Presentation is loading. Please wait.

HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition.

Similar presentations


Presentation on theme: "HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition."— Presentation transcript:

1 HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } Complete the following (this can be done in your Google drive or on paper and brought to class): “ TOPIC: Create an IF ELSE statement that gives a result of “pass” or “fail” with the pass mark of 50.” 1.Create a Pseudocode to help ‘plan’ your if else statement (Look at slide 10 for an example) 1. Create an IF ELSE statement in this Unity beginning script (decide whether to put it in function start or function update (if you get stuck look at slide 12)

2 THIS IS THE TEMPLATE FOR YOUR HOMEWORK #pragma strict function start () { } function update () { } If wanted to have the code execute one time only, then you will need to put you IF ELSE statement in the function start area. All script needs to sit inside the { } All script in the function update will have the opportunity to run over and over for as long as the script inside the { } wants to

3 LETS TRY ONE OURSELVES Using Unity JavaScript create a Pseudocode to help ‘plan’ your if else statement. “ TOPIC: Create an IF ELSE statement that gives a result of “pass” or “fail” with the pass mark of 50. Pseudocode (coding design tool, helps me visualize what I want in my script) IF MARK >= 50 THEN PRINT “You pass” ELSE PRINT “You fail” END IF

4 MY ANSWER EXAMPLE #pragma strict var mark= 75; function Start() { if (mark >= 50) { Debug.Log ("You pass"); } else { Debug.Log("You fail"); } } function Update() { } I have created my variable, naming it ‘mark’ I gave it some information/value mark=75. So now whenever I type the word mark in my script the value 75 will replace the word. IF mark is greater than or equal to 75 then the computer console will print ‘You pass’ Else/ otherwise (if the input is less than 50) print ‘You fail’ to the computer console.

5 DEBUGGING

6 WHERE DID THE TERM DEBUGGING COME FROM? On September 9th, 1947 a woman, Grace Hopper, was working on a computer at Harvard University. The computer was one if those main frame computers that were very large. When the computer stopped working, she began to investigate the problem. After removing one of the panels she found a moth caught between two relay points. When she removed the moth and put the panel back in place, the computer functioned properly again. Grace reported that the computer was debugged.

7 DEBUGGING What is debugging in programming? Debugging means to check and test your script/work and ensure that is it doing what was planned without any faults, so that you correctly achieve your purpose. Debugging is looking for errors in the script that: 1.Stop the script or part of from working e.g. misspelling a function/variable name, therefore the code cannot be executed. 2.The script works but what you wanted the script to achieve in fact doesn’t. e.g. “” where not included therefore the script will play but the information you wanted to appear on screen won’t because there is an error

8 WHAT COULD WE BE LOOKING FOR? Check all possible processing pathways through the program, if I have an IF statement that needs to print x when the user puts in y does this happen?. Also the visual interface needs to be tested (that is testing that what you expect to see is what you in fact see). Lastly does what you planned suit your original expectations? Simple syntax errors in JavaScript to look out for: -Brackets are in the right place and the correct bracket was used either () or {} or [] -Capital and lower case letters are correct -When referring to a variable is it spelt correct and has the right upper and lower case setup -Are there ; (semi colons) either in the wrong place or missing -Do you need to space where there isn’t one -Have you used the right symbols > < + = - // # “” -AND MANY MORE (refer to page 239 of Information technology textbook)

9 HOW TO DEBUG There are a few ways to check for errors. 1.Play the script and view the result. 2.Scan through the script and look for missing content 3.Take all of the script out and replace it a bit at a time, while playing the script (add script press play, add script press play etc. does each part work) 4.Use debugging software (e.g. Unity has its own) You simply put your script in and the program will check for particular errors. 1.Record a test table and keep a record…

10 Test DataExpectedActualComments The section of data that is tested What to expect the result of this What actually happened Where there any changes you made to ‘fix’ the issues. If there weren’t note that and include why it doesn't’t need to be fixed etc. TESTING TABLE Testing tables are like keeping a checklist; writing it in table form keeps the information relevant and neat. Types of testing include: Input testing, data-validation testing, process testing, output testing and storage testing

11 IF/ELSE COFFEE SCRIPT #pragma strict var coffeeTemperature:float = 85.0f; var hotLimitTemperature:float = 70.0f; var coldLimitTemperature:float = 40.0f; function Update() { if(Input.GetKeyDown(KeyCode.Space)) TemperatureTest(); coffeeTemperature -= Time.deltaTime * 5f; } function TemperatureTest() { // If the coffee's temperature is greater than the hottest drinking temperature... if(coffeeTemperature > hotLimitTemperature) { //... do this. Debug.Log("Coffee is too hot."); } // If it isn't, but the coffee temperature is less than the coldest drinking temperature... else if(coffeeTemperature < coldLimitTemperature) { //... do this. Debug.Log("Coffee is too cold."); } // If it is neither of those then... else { //... do this. Debug.Log("Coffee is just right."); }

12 FOR LOOPS FOR LOOPS circle through a block of code and will continue to repeat the code according to the amount of times requested. Therefore instead of writing the same code over and over with one slight change, FOR loops re read and execute the code for you. Format: (set initial variable; condition; action on the variable) (rule)

13 EXAMPLE - LOOPING (FOR) #pragma strict var numEnemies : int = 3; function Start () { for(var i : int = 0 ; i < numEnemies ; i++) { Debug.Log("Creating enemy number: " + i); } (set initial variable; condition; action on the variable)

14 WHILE LOOPS While Loops are very similar to FOR loops as they too execute the same code over and over. However they differ in that WHILE loops are used when the programmer is unsure how many times they want the code to be executed. Format: while (condition/expression) { Statement/s to be executed if expression is true }

15 #pragma strict var numEnemies : int = 3; function Start () { while (i < 10) { Debug.Log ( "The number is " + i); } }


Download ppt "HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition."

Similar presentations


Ads by Google