Java Script/Basic Code
From r00tedvw.com wiki
(Difference between revisions)
(3 intermediate revisions by one user not shown) | |||
Line 14: | Line 14: | ||
;if/else | ;if/else | ||
:used to send code down different paths | :used to send code down different paths | ||
− | if ( | + | if( condition) { |
− | + | code code code; | |
− | + | } else if { | |
+ | code code code; | ||
+ | } else { | ||
+ | code code code; | ||
+ | } | ||
;var | ;var | ||
:variable that can be determined or given | :variable that can be determined or given | ||
var MeaningofLife = 42 | var MeaningofLife = 42 | ||
+ | ;function | ||
+ | :follow the same instructions by calling on a single variable. | ||
+ | //This is what a function looks like | ||
+ | |||
+ | var divideByThree = function (number) { | ||
+ | var val = number / 3; | ||
+ | console.log(val); | ||
+ | }; | ||
+ | |||
+ | //On line 11, we call the function by name | ||
+ | //Here, it is called 'dividebythree' | ||
+ | //We tell the computer what the number input is (ie. 6) | ||
+ | //The computer then uses the code inside the function | ||
+ | divideByThree(12); | ||
+ | |||
+ | ;loop | ||
+ | :loops a specified response until condition is met | ||
+ | for(var i = 100 ; i >= 0 ; i -=5 ) { | ||
+ | console.log(i); | ||
+ | } |
Latest revision as of 22:34, 11 March 2013
Confirm pop-up (with ok or cancel response)
confirm("I feel awesome!");
Input prompt pop-up
prompt("Enter your name:");
Print out values for each line of code
console.log()
Information pop-up
alert("")
- Data Sets
- numbers (3, 42, etc)
- strings ("This is a string", "42", "is also a string")
- Booleans
- true or false statements, such as (7<10) or (10<7)
- if/else
- used to send code down different paths
if( condition) { code code code; } else if { code code code; } else { code code code; }
- var
- variable that can be determined or given
var MeaningofLife = 42
- function
- follow the same instructions by calling on a single variable.
//This is what a function looks like var divideByThree = function (number) { var val = number / 3; console.log(val); }; //On line 11, we call the function by name //Here, it is called 'dividebythree' //We tell the computer what the number input is (ie. 6) //The computer then uses the code inside the function divideByThree(12);
- loop
- loops a specified response until condition is met
for(var i = 100 ; i >= 0 ; i -=5 ) { console.log(i); }