Web Programming and Problem Solving презентация

Слайд 2

Usually, JavaScript is used in web pages… for now, we will just concentrate

on basics of the language
A JavaScript Interpreter:
http://www.webtoolkitonline.com/javascript-tester.html

Getting Started with JavaScript

Слайд 3

Try the following program:

A First Program

var a;
var b;
var c;
a = 13;
b = 200;
c

= a + b;
document.write(c);

Слайд 4

var a;
var b;
var c;
a = 13;
b = 200;
c = a + b;
document.write(c);

In programs,

variables are labels that represent places where data is stored
The data that is stored inside a variable is called its value

Values and Variables

What are the variables and their values in this program?

Слайд 5

To tell the computer to set aside storage space for a variable, you

should declare the variable

Declaration

In JavaScript, you declare variables using the var keyword

var a;
var b;
var c;
a = 13;
b = 200;
c = a + b;
document.write(c);

Слайд 6

To change the value stored in a variable, you assign it a new

value using the equals sign

Assignment

Examples of assignments

var a;
var b;
var c;
a = 13;
b = 200;
c = a + b;
document.write(c);

Слайд 7

Expressions are things that can have a value

Expressions

Examples:
Variables
Numbers and other literals
Expressions joined together

by operators (e.g., +, -, *, /)

var a;
var b;
var c;
a = 13;
b = 200;
c = a + b;
document.write(c);

What expressions do you see in this program?

Слайд 8

Statements are the elements in code that perform individual tasks in sequential order
Think

“a line of code”
Often end with a semicolon
Examples:
Declarations
Assignments
Function calls

Statements

var a;
var b;
var c;
a = 13;
b = 200;
c = a + b;
document.write(c);

What are the statements in this program?

Слайд 9

Arithmetic operations (+, -, *, /) can be used
Order of operations: * and

/ take precedence over + and –
Exercise: What values do these produce?
100 + 4 * 11
(100 + 4) * 11
115 * 4 – 88 / 2

Working with Numbers

Слайд 10

Add code to the following program to convert Fahrenheit to Celsius using the

formula:
(F – 32) * 5/9 = C

Exercise 1

var fahr = 100;
var cels;
// add your code here
document.write(cels);

Слайд 11

Add code to the following program to calculate the average of a, b,

and c

Exercise 2

var a = 10;
var b = 20;
var c = 25;
var avg;
// add your code here
document.write(avg);

Имя файла: Web-Programming-and-Problem-Solving.pptx
Количество просмотров: 23
Количество скачиваний: 0