Skip to content

Latest commit

 

History

History
116 lines (68 loc) · 2.75 KB

File metadata and controls

116 lines (68 loc) · 2.75 KB

Javascript

  • the javascript make the web pages more interactive we can use javascript in:

  • we can select any element, attributes, text on html using javascript for example Select the text inside all of the <hl> elements on a page

  • we can add to the content of the element, attributes, text for example Change the size or position of an <img> element

  • we can specify a set of steps for the browser to follow

  • we can specify that a script when it should be run like when a specific event has start

example for javascript in the browser

we can access, modify,program and react by using javascript like:

  1. Slideshows

  2. forms

  3. reload part of a page

  4. filtering data

Script

A script is a series of instructions that a computer can follow to achieve a goal.

  • to write a script we need to state the goal of the script and make list of task to achieve it in a steps:
  1. DEFINE THE GOAL

  2. DESIGN THE SCRIPT

  3. CODE EACH STEP

Expressions

  • An expression evaluates into (results in) a single value, there are two types of expressions:
  1. expression that just assign a value to a variable var color = 'beige';

  2. expression that use two or more values to return a single value var area = 3 * 2; (the value is now 6)

Operators

they allow programmers to create a single value from one or more values.

type of operators :

  • ARITHMETIC OPERATORS

perform basic math area = 3 * 2; and we can use

Name Operator
addition +
substraction -
division /
multiplication *
increment ++
decrement --
modulus %
  • STRING OPERATOR

It is used to join the strings on either side of it greeting= 'Hi' + 'Molly';

  • ASSIGNMENT OPERATORS Assign a value to a variable color = 'black'

  • COMPARISON OPERATORS

Compare two values and return true or false buy = 3 > 5; false

  • LOGICAL OPERATORS

Combine expressions and return true or false buy= (5 > 3) && (2 < 4); true

Functions

functions let us group a blocks of codes together to perform a task wen can

perform the funtction that contain the block of code by calling the function

and repeated it anyware using the call function rathar than write the code again.

type of Functions:

  • Expression Function:

example of the syntax

var getAge = function () {
console.log('my age is 20 years');
 }
  • Declaration Function

example of the syntax

function getUserName() {
var name = prompt('Hello you could you please tell me your name??');
console.log(name);

** calling the function**

we can run the code inside the curly brackets with just one line of code

getAge();

getUserName();