14
JavaScript Informatics for economists I

JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Embed Size (px)

Citation preview

Page 1: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

JavaScript

Informatics for economists I

Page 2: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Introduction

Programming language used in web pages.

Simple and easy to use – written in HTML document.

Client scripting language – script is sent with HTML document to web browser (client).

JS is not Java. It has just similar syntax.

Page 3: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Characteristics

Interpreted lang. – no compiling Object oriented – uses web browser

and built-in objects Browser dependent Case sensitive Syntax is similar to C or Java

language.

Page 4: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Limitations

Works in web browser only. User can disable JS in browser. Many different JS versions. Cannot access to files or system

object. Cannot save data.

Page 5: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Writing JS scripts

Use <script> </script> tags. Example:

<body>

<script>

document.write(“Hello world!”);

</script>

</body>

Page 6: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

JS variables

Initialized when firstly used. Case sensitive Example:

var x, y;

x=10;

y=”Hallo”;

Page 7: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

JS operators

value assignment:

=

numeric operators:

+, -, *, /

logical operators:

==, !=, <, >, <=, >=

Page 8: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Conditions

Used to decide whether the expression is true or not

if (expression) {commands when true;

} else {commands when false;

}

Page 9: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Cycles

Used to repeat commands.while (expression) {

commands;

}

for (initial value, condition, increment){

commands;

}

Page 10: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Functions

Frequently used part of program

function name(params){

commands;

return value;

}

Page 11: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Object document

Most frequently used object in JS. Contains everything on the page.

document.forms

document.images

Page 12: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Object Math

Used with mathematical operations

Math.abs(x)

Math.exp(x)

Math.pow(a,x)

Math.sqrt(x)

Math.PI

Page 13: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Events

Activated when user does actiononLoad – loading document

onClick – cliking on object

onDblClick – doubleclicking on object

onMouseOver – move mouse over object

onMouseOut – move mouse out of object

onFocus – focusing object (activating)

onKeyPress – pressing key on object

onSubmit – pressing submit form button

Page 14: JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client

Communication with user

Print information: alert(“some text”); document.write(“some text”);

Get data from user: prompt(“prompt text”,”initial value”);

parseInt, parseFloat Use forms:

<input type=”text” name=”id”>