Debugging No readings. 2 What's The Proper Indentation? function max(x,y) { if (x<y) { return y;} else { return x;} } alert(max(10,12));

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Introducing JavaScript
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
Ten debugging techniques. The execution process Execution proceeds in a standard series of steps Compute values of subexpressions first Then call value.
Tutorial 10 Programming with JavaScript
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Debugging JavaScript CS346. IE Javascript Debugging Aids From IE6 on default: no debugging aid for Javascript Change setting: – Tools > Internet Options.
Javascript and the Web Whys and Hows of Javascript.
05/09/ Introducing Visual Basic Sequence Programming.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
WaveMaker Visual AJAX Studio 4.0 Training Troubleshooting.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
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.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
Active-HDL Interfaces Debugging C Code Course 10.
Hello World in the Forte IDE An introduction to the Forte IDE (integrated development environment) writing the classic “Hello World” program in Java.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Conditional Statements.  Quiz  Hand in your jQuery exercises from last lecture  They don't have to be 100% perfect to get full credit  They do have.
Loops.  (No Quiz)  Hand in Assignment #1  Last chance for Q+A on the midterm  Loops 2.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
1 JavaScript in Context. Server-Side Programming.
JavaScript Challenges Answers for challenges
Debugging It is what you do. Debugging Where your time is spent: 1 st place: documentation 2 nd place: debugging Most valuable skill: Debugging!
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Chapter 4 Murach's JavaScript and jQuery, C4© 2012, Mike Murach & Associates, Inc.Slide 1.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Logical Operators.  Quiz  Let's look at the schedule  Logical Operators 2.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
Debugging using By: Samuel Ashby. What is debugging?  A bug is an error in either a program or the hardware itself.  Debugging is first locating and.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
BIT116: Scripting Lecture 06
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Eclipse Navigation & Usage.
Testing and Debugging.
Computer Programming I
Javascript Game Assessment
Tonga Institute of Higher Education
Introduction to TouchDevelop
Tutorial 10 Programming with JavaScript
An Introduction to Debugging
Running a Java Program using Blue Jay.
CS105 Introduction to Computer Concepts JavaScript
Workshop for Programming And Systems Management Teachers
Presentation transcript:

Debugging No readings

2 What's The Proper Indentation? function max(x,y) { if (x<y) { return y;} else { return x;} } alert(max(10,12));

3 When To Indent? Everything between a opening and closing curly brace should be indented in. The closing curly brace should be on its own line and should line up with the start of the code block. if (age < 21) { alert("Intruder alert!"); alert("Unauthorized attempt to drink alcohol!"); } if (age < 21) { alert("Intruder alert!"); alert("Unauthorized attempt to drink alcohol!"); }

4 When To Indent? Notice that the indentation rules are the same as the HTML indentation rules. Nothing new to learn! if (age < 21) { alert("Intruder alert!"); alert("Unauthorized attempt to drink alcohol!"); } JavaScript First! If you're not first, you're last. HTML

5 Opening Curly Brace There are two standard ways to open a code block. Pick whichever you prefer and stick with it. if (age < 21) {... } if (age < 21) {... }

6 JSLint ( Make sure the option "Strict white space" is checked. Change the number for "Strict white space indentation" to whatever number of spaces you like.

7 Using JSLint Ignore error messages that do not pertain to indentation.

8 Proper Indentation function max(x, y) { if (x < y) { return y; } else { return x; } alert(max(10, 12)); function max(x, y) { if (x < y) { return y; } else { return x; } alert(max(10, 12)); Remember: Don't mix spaces and tabs when indenting!

Debuggers

10 Why Won’t It Toast? You arrive at your dorm after a thought- provoking lecture of INFO/CSE 100. To feed your brain, you put some bread into your toaster oven and set the dial for 5 minutes. The toaster oven ticks away. After five minutes, the toaster oven dings. You take the bread out, but it’s not even toasted. What do you do?

11 How To Debug Find out what values are stored in the variables at different points in time. Never assume anything.  Don't just say that a variable contains a certain value. Prove it! Use popup boxes to display the variable or watch the variable in the debugger. Narrow down the location of the problematic code.  Delete code until you get it in a working state, and then add in the broken code in phases.

12 How To Debug Simulate the computer on paper. Go line by line.  Can also use the debugger go line by line. Make sure you understand what every single line does.  Computers are neither magical nor mysterious. Everything can be explained!

13 Get Firebug Firebug:  Firefox:  While you're at it, consider getting Ad Block Plus. 

14 Setting Up Firebug 1.After installation, load one of your HTML pages into Firefox. 2.Click the picture of the grey bug on the bottom right of the window. 3.Firebug will open up. Click on the "Script" tab and then select the "Console" and "Script" checkboxes in the window. Apply the settings.

15 Understanding Error Messages document.getElementById(" ") is null  The given identifier,, does not exist. Typo perhaps? is not a function  Most likely cause is spelling or capitalization error. is not defined  Most likely cause is spelling or capitalization error or copying from example code without changing the names.

16 Understanding Error Messages As the computer is not omniscient, not all error messages are exact. What's wrong here? Adding semi-colons before the statement does not fix the problem.  if is misspelled. Firebug can miss some errors.  A debugger should be only used as an aid, not a panacea.

17 Breakpoint breakpoint: intentional stopping or pausing place in a program, put in place for debugging purposes To add a breakpoint, click on the filename on the top bar in Firebug and select the JavaScript file.

18 Adding Breakpoints Clicking on a number on the left-hand side toggles the appearance of a red circle (a breakpoint).

19 Breakpoints When the program is running, it will stop on any line that has a red circle. All variables that the computer "knows" at that point in time before the line is executed will appear on the right-hand side.

20 Debugging Continue executing program until next red circle or end of program Execute this line and stop at start of next line

21 Exercise How old are you? <input type="button" value="Can I Enter The Club?" onclick="checkAge();" /> function checkAge() { var guestAge = document.getElementById("age").value; if (guestAge >= 21) { alert("Welcome. Rock on!"); } else if (guestAge = 20) { alert("Close enough; we'll sneak you in."); } else { alert("I'm sorry, you can't party with us. Scram!"); } HTML JavaScript

22 Solution How old are you? <input type="button" value="Can I Enter The Club?" onclick="checkAge();" /> function checkAge() { var guestAge = document.getElementById("age").value; if (guestAge >= 21) { alert("Welcome. Rock on!"); } else if (guestAge == 20) { alert("Close enough; we'll sneak you in."); } else { alert("I'm sorry, you can't party with us. Scram!"); } HTML JavaScript

23 Exercise Text: Repeat times function display() { var text = document.getElementById("text").value; var quantity = document.getElementById("time").value; for (var i = 1; i <= times; i++) { output = sentence + " "; } document.getElementById("text").innerHTML = output; } HTML JavaScript

24 Solution Text: Repeat times function display() { var text = document.getElementById("sentence").value; var quantity = document.getElementById("times").value; var output = ""; for (var i = 1; i <= times; i++) { output += text + " "; } document.getElementById("text").innerHTML = output; } HTML JavaScript