21 terms

The New Boston Javascript

STUDY
PLAY

Terms in this set (...)

script tag
<script type="text/javascript"></script>
comment
/ comment goes here /
print on screen statement
document.write("i love ham");
variable
var x = 23;

Example:
var x = 23;
document.write(x);

prints out: 23
string
var tuna = "text in here";

Example:
var tuna = "tuna is her";
document.write(tuna);

prints out: tuna is here
escape characters for strings
\additional text\

Example
var tuna = "john said, \"boy do i love bessie.\" ";
document.write(tuna);

prints out: john said, "boy do i love bessie."
null
var tuna = null;

null means empty

Example
var tuna = null;
document.write(tuna);

prints out:
using strings with numbers
Example:

var name = "Bucky";
var age = 24;
document.write(name + "is my name and my age is" + age + ".");

prints out: Bucky is my name and my age is 24.
function
function name(){
code goes here
}

Example
function funky(){
alert("Ouch!!!);
}

funky();

prints out: Ouch!!!
how to make a pop up appear?
alert("text");
form tag html
<form> </form>
form tag with function
Example

function funky(){
alert("Ouch!!!);
}

<form>
<input type="button" value="touch me" onclick="funky()">
</form>

prints out: button that says touch me appears. when clicked a popup appears that says Ouch!!!
Function with a parameter
Example

function meatball(x){
alert("i love" + x);
}

meatball(bacon);

prints out: i love bacon
Function with multiple parameters
Example

function apples(one, two){
document.write(one + "is better than " + two);
}

apples("bucky", "hobart");

prints out : bucky is better than hobart
return statement
Example

function tooeasy(){
return "gametime";
}

tooeasy();

prints out:

explanation: return just returns the value but does not print it out
return statement cont.
Example

function addNumbers(a,b){

var c = a + b;
return c;

}

document.write(addNumbers(3,6);

prints out: 9
Call a Function from another function
Example:

function doFirst(){
document.write("I am first bo!");
}

function doSecond(){
document.write(" 222222!!!");
}

function start(){
doFirst();
doSecond();
}

start();

prints out: I am first bo! 222222!!!
Global Variable
Variable created outside the body of a function.

Example

var girl = "kelsey";

function spit(){
document.write(girl);
}

spit();

document.write(girl);

prints out: kelsey
kelsey
Local Variable
Variable created inside the body of a function.

Example

function spit(){
var girl = "kelsey";
document.write(girl);
}

spit();

document.write(girl);

prints out: kelsey
Global vs Local Variable
Global variables can be called anywhere while local variables can only be called within the function in which it is declared.
tutorial 12
...