Notes for Codefellows Code 401 301 201 and 102
how much detail you need to tell it to do something
a script is like a resipes/handbook/manual - series of instructions that a computer follows to achieve a goal.
each time the script runs it might only use a subset of all the instructions
computers approach tasks in a different way than humans, so your instructions must let the computer solve the tasks programmatically
an expression results in a single value - 2 types
expressions that use 2 or > values to return a single value
variables are used to temporarily store data stored in the script arrays are special types of variables that store more than 1 piece of info JS - numbers(0-9) , strings(text) , Boolean (t/f)
functions - group a series of statements 2 perform specific task use function 2 repeat part of script - no re write code
example insert new text into an html - by grabbing onto an ID
function sayHello() {
document.write('Hello you');
}
sayHello();
function getArea(width,height) {
return width * height;
}
getArea(3,5);
or
width = 3;
height = 5;
getArea(width, height);
function calcArea(width, height) {
` var area = width * height;
return area; makes the script stop and return to where it was
}
var wall_1 = calcArea(3, 5);
var wall_2 = calcArea(8, 5);`
function getSize(width, height, depth) {
` var area = width * height;
var volume = width * height * depth;
var sizes = [area, volume];
return sizes;
}
var area51 = getSize(3,2,4)[0];
var volume51 = getSize(3,2,4)[1];`
function area(width, height) {
` return width * height;
}
var size = area(3, 4);`
compared to
var area = function(width, height) {
` return width * height;
};
var size = area(3, 4);`
first one (function declaration) can be called before script runs over it where as the second one (function expression) cannot