Professional Documents
Culture Documents
Basics Of JS:
• Any Line of Code is Called Statement
• Each Stmt should end with a semi-colon ;
• document.write ( 'Welcome!' );
• How to add Comments?
○ Multi-Line Comments eg for Paragraphs
§ /* comments words etc */
○ Single-Line Comments eg for words in one-line
§ // …comment
○ Set Function Name to quantity
§ var quantity;
§ Function name can start with anything such as $ sign but not numbers
§ Mostly Starts with Alphabets or $ in some cases
// is a single-line comment
/* Multi-Line Comment */
Js is a Case-Sensitive
s
// is a single-line comment
/* Multi-Line Comment */
Js is a Case-Sensitive
Var quantity; // Var is a Variable Keyword, and Quantity is a Variable Name "Also Calle
• Setting Values
○ Quantity = 3; // = is an assignment operator
Types of Data
• Numbers
○ 0.75
• String
○ 'Hi, Ivy' or 'My-Name'
○ Can use Single Quite or Double ' ' or " "
• Boolean
○ True or False
○ Be Careful if written like 'True' this is STRING cuz the single-quite is used!!!
Var pi;
Pi = 3.14; // Second Way Involve two-lines
Var lang = "Python 3"; // We're setting new variable called lang stores STRING
Arrays
Colors = ['Pink' , 'Yellow' , 'Green']; // Remember first element = 0, but the length tho
Var width = 3;
Var height = 2;
Area = width * height;
// If you put any numbers between quotes won't get result since it converted to STRING
// Mathematical Operations only happens when there are Numbers Type of Data
ed Identifier"
ough is 3
G
Var width = 3;
Var height = 2;
Area = width * height;
// If you put any numbers between quotes won't get result since it converted to STRING
// Mathematical Operations only happens when there are Numbers Type of Data
JS Function
Var el = document.getElementByID('cost');
El.textcontent = '$' + total;
….
Colors.log("Welcome to CP 202");
Functions:
• Makes our life easier, makes the code reusable
G
• Var shipping = 0.5 * (13+1); // inside the bracket is done first!!
Functions:
• Makes our life easier, makes the code reusable
• Let you group a series of statements together to perform a specific task
• Function should not have lot of code "Maximum of one-page screen
Declaring a Function:
function sayHello( ) {
Document.write ( 'Hello');
}