Variables and data types Flashcards
Example languages that run directed on the OS
C++, Java, C#, Objective-C
Example scripting languages that run through another application
ActionScript, Javascript, VBScript
actionscript runs on
flash
javascript runs
through browsers
VBscript runs
on MS office
scripting languages are ______ languages
interpreted
languages that have curly brackets {, } or semi colons ; are languages that influenced by __________ programming
C
write script for a little popup thats says Hello World
alert(“Hello World”);
variables are used to ….
hold data
var year;
variable =
year
var date;
variable =
date
THIS ENTIRE COURSE IS BASED ON
Javascript!
OTHER LANGUAGES MAY BE DIFFERENT
Rules for writing variables
IN JAVASCRIPT
1) Can use letters
2) Can use numbers
3) Can use $ (dollar sign)
4) Can use _ (underscore)
5) cannot start variable with a number sign
creata a variale that is = 2011
var year;
year = 2011;
var year;
year = 2011;
shorten this statement
var year = 2011;
technically:
year = 2011;
is equivalent to var year = 2011;
because javascript will look for a variable called year and will assume year = 2011; = var year = 2011;
are variables case sensitive?
YES
shorten
var month;
var day;
var year;
var month, day, year;
variable data types
name a few basics
1) integer (whole number: 55, 345, 65465)
2) floating point number (has decimal: 55.33, 5564.3355)
3) single character (a, B, f, g)
4) string( bunch of characters)
5) boolean (true or false)
What’s wrong with this?
var phrase = “He said “that’s fine” and left”;
Javascript will assume you meant
var phrase = “He said “
and that’s fine” and left”; is separate
how to fix
var phrase = “He said “that’s fine” and left”;
var phrase = “He said "that’s fine”\ and left”;
use backward slash
using variables, write a script to subtract 100 from 200
var a = 100; var b = 200; var result = b - a;
using variables, write a script for 300 divided by 100 decided 8
var a = 300; var b = 200; var c = 8; var result = a / b; var result2 = result/c
or
var a = 300; var b = 200; var c = 8; var result = a / b / c;
shorten
score = score + 100;
score += 100;
shorten
score = score - 48;
score -= 48;
a++;
is used for
an increase of an increment of 1
it is equivalent to a+=1; or a = a+1;
++ is called the
increment operator
– is called the
decrement operator
does javascript care about whitespace?
NO, because of the semi solon ; signals the end of statement
what do you write in javascript to cause a line break?
\n
what do you write to start a comment?
//
this only works with 1 line
how do you have a multiple line comment?
Starts comment > /*
*/