Lecture Supp (11) Week 10 lecture exercise [Given Code] LectEx10_ShowPrimeNumbers.html If we remove both “var” for i, then the new window shows ‘3’ repeatedly.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Lecture 4: Javascript Basics Javascript is a scripting language based on pieces of C, C++, shell scripts, Pascal, Java, etc. Scripts – loosely typed C++
Chapter 3 Program Design And Branching Structures.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Debugging Introduction to Computing Science and Programming I.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Lecture Exercise (9) CS1301 Introduction To Computer Programming (07-08 Semester B) Random Student Numbers 1: 2: 3: 4: 5:
Page 1 Lecture Exercise (Wk4) CS1301 Introduction To Computer Programming (07-08 Semester B) Question 2 According to the following.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Page 1 Lecture Exercise ( Wk2) CS1301 Introduction To Computer Programming (07-08 Semester B) Question 1. MATCHING: html comments.
Introduction to a Programming Environment
Which is better?. Assume s1 and s2 are Strings: A.if (s1 == s2) {... } B.if (s1.equals(s2)) {... }
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2010SCM-CityU1.
CIS101 Introduction to Computing Week 09 Spring 2004.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Introduction to JavaScript for Python Programmers
1 CS101 Introduction to Computing Lecture 19 Programming Languages.
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Programming Translators.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
CS101 Introduction to Computing Lecture Programming Languages.
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.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2012SCM-CityU1.
CIS 234: LOOPS Adapted from materials by Dr. Donald Bell, 2000 (updated April 2007)
PHY 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Program Design (or Why C is really not difficult?) A/Prof Anthony Tung Department of Computer Science School of Computing NUS
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
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.
INTRODUCTION TO CSS. TOPICS TO BE DISCUSSED……….  Introduction Introduction  Features of CSS Features of CSS  Creating Style Sheet Creating Style Sheet.
CS162 Week 1 Kyle Dewey. Overview Basic Introduction CS Accounts Scala survival guide.
Introduction to programming Carl Smith National Certificate Year 2 – Unit 4.
Hints on debugging
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
5.01 Understand Different Types of Programming Errors
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
Learn to code- JavaScript. Prt 1. TUTOR: DRKALMENIUS.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Lecture Exercise (Wk4) CS1301 Introduction To Computer Programming (11-12 Semester B) Page 1 Question 2 (a)Complete the code.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
CS1301 Introduction To Computer Programming (11-12 Semester B) Lecture Exercise (Wk8) Q.1 Write the code that asks the user.
Learning Javascript From Mr Saem
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Random Student Numbers 1: 2: 3: 4: 5: Generate random student numbers: Random Student Numbers 1: : : :
Topic 02: Introduction to ActionScript 3.0
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter 10 Programming Fundamentals with JavaScript
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Problem Identification
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
CS101 Introduction to Computing Lecture 19 Programming Languages
Lecture 2 Introduction to Programming
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Chapter 10 Programming Fundamentals with JavaScript
CS1100 Computational Engineering
Introduction to TouchDevelop
CSS.
JavaScript 101 Lesson 8: Loops.
Presentation transcript:

Lecture Supp (11) Week 10 lecture exercise [Given Code] LectEx10_ShowPrimeNumbers.html If we remove both “var” for i, then the new window shows ‘3’ repeatedly (can’t stop). Why? CS1301 Introduction To Computer Programming (07-08 Semester B) P. 1

If we remove both “var” for i, then the new window shows ‘3’ repeatedly (can’t stop). Why? HINT / DISCUSSION: i used in showPrimeNumbers and isPrime should be different variables. (1) If both “var” are removed. Then “i=start;” (line 21) will automatically add a property “i” of the window object ( window.i ) (This will be automatically done because i has not been declared as a variable or anything). Later, at lines 8-12, “i=2” will actually refer to window.i. (The same as lines 22-25). That is, both isPrime() and showPrimeNumbers() share the same i !! Javascript is convenient (flexible, less constraints, loose in syntax), BUT easy to create problem (easily go wrong, bad style / habit). So, actually, Javascript programmers need to be serious about what he is writing. Traditional languages like Pascal, C++: Tight but safe to create proper code!! (Easier to debug!!) – eg. must add semi-colon, variables must be declared. (2)[ Interested students only!! ] But why show ‘3’ repeatedly? Answer: Line 23: Check whether window.i (= 50) is prime ==> false ==> won’t write (ie. won’t run line 24) But isPrime() has changed window.i has to 2 Line 25: i++; will update window.i to 3.. P. 2