by :Before getting deep in the javascript this is a quiqk refresh for HTML & CSS:
Before you learn how to read and write the JavaScript
language itself, you need to become familiar with some key
concepts in computer programming and they are :
What is a script and how do I create one?
Sicript could be :
A browser may use different parts of the script depending on how the user interacts with the web page. Script can run different sections of the code in response to the situation around them.
To write a script, you need to first state your goal and then list the tasks that need to be completed in order to achieve it.
Start with the big picture of what you want to achieve, and break that down into following steps :
Designing a script diagram:
![]()
Every step for every task shown in a flowchart needs to be written
in a language the computer can understand and follow.You should focus in :
You need to get to work with the: • Vocabulary: The words that computers understand • Syntax: How you put those words together to create instructions computers can follow
You need to learn to “think” like a computer because they solve tasks in different ways than you or I might approach them.
So To approach writing a script, break down your goal into a series of tasks and then work out each step needed to complete that task (a flowchart can help).
1. EXPRESSIONS:
two types of expressions:
var color = 'beige';var area = 3 * 2;2. OPERATORS:
color = 'beige';
area = 3 * 2;
greeting= 'Hi 1 + 'Mol ly';
buy = 3 > 5;
buy= (5 > 3) && (2 < 4);
- Arithmetic operators :
Example for arithmetic operator: // Subtotal is 70 var subtotal (13 + 1) * 5; // Shipping is 7 var shipping 0.5 * (13 + 1) ; // Total is 77 var total subtotal + shipping ;
var el Sub document .getElementByid(‘ subtotal ‘) ; elSub .textContent =subtotal ;
var elShip = document .getElement Byid(‘shi ppi ng ‘) ; elShip.textContent =shipping;
var elTotal = document .getElementByid(‘total ‘); elTotal .textContent =total;
- Srting operator :
Example: var greeting= ‘Howdy ‘; var name= ‘Mol ly’ ; var welcomeMessage = greeting+ name+ ‘!’; var el = document.getElementByld(‘greeting’); el .textContent = welcomeMessage;
- Function and method :
If different parts of a script repeat the same task, you can reuse the function.
Calling the function: you need to give your function a name , and the name should describe the task it is performing.So you could o ask the function to perform its task later and when you ask it to perform its task that’s known as calling the function
Code block : the steps/statments that the function need to perform in order to perform its task.
Parameters : it is the informations that are provided to the function in order to achieve a given task.
Return value : When you write a function and you expect it to provide you with an answer, the response is known as a return value.
Example: //variable var msg = ‘Sign up to receive our newsletter for 10% off!’; //function function updateMessage() { var el = document.getElementByld(‘message’}; el .textContent = msg; } //calling the function updateMessage(};
References:
@Jon Duckett/JAVASCRIPT