Chapter01 - Chapter 1 JavaScript Programming Basics 1.1...

Info icon This preview shows pages 1–14. Sign up to view the full content.

JavaScript Programming Basics Chapter 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

1.1 What is Programming?
Image of page 2
The Program Development Cycle Analyze the problem What information are you given? What information is needed to get desired results? Design a program to solve the problem Include step-by-step instructions Can use flowcharts or pseudocode Code the program Test the program At any time you find a flaw, revise!
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

1.2 The Structure of a Program
Image of page 4
Input-Processing-Output Input: prompts previous values other files Processing: what the program does with input and other information Output: display on screen information sent to other places
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Prompts Prompt: var name = prompt("Please enter your name"," "); User sees: (Internet Explorer) (Firefox) After entering “Fiona” , the variable name holds the value “Fiona”
Image of page 6
Processing the Input Example: <script type="text/javascript"> var name = prompt("Please enter your name"," "); var greeting = "Hello there, " + name + "!"; </script> If the user enters “Fiona” , the variable name = “Fiona” and the variable greeting = “Hello there, Fiona!”
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Output Example: <script type="text/javascript"> var name = prompt("Please enter your name"," "); var greeting = "Hello there, " + name + "!"; document.write( greeting ); </script>
Image of page 8
The Control Structures The sequential (or sequence) structure statements execute in sequence The decision (or selection) structure statements execute if a condition is true if not, either nothing happens or other statements execute The loop (or repetition) structure statements execute until a condition is no longer true
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

The Control Structures The decision (or selection) structure The loop (or repetition) structure
Image of page 10
1.3 Data Types and Operations on Data
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Numerical Data Numbers are values that can be processed and calculated. Many languages make a distinction between integers and floating point numbers. JavaScript: when a number is stored in a variable, it is initially treated as a floating point number. All numbers in JavaScript are initially stored as the numerical data type. When a number is entered into a prompt box, it is initially stored as a text value. It cannot be used in a calculation. It must be turned into a numeric value to use in a calculation.
Image of page 12
String Data Strings are a series of keyboard characters enclosed in quotation marks. Strings can consist of words, phrases, sentences, and even whole paragraphs. A string can also be a single character such as a letter or a punctuation character.
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern