Modular, loops, strings. Flashcards

1
Q

difference between parameter and argument.

A
  • argument is more specific than the parameter

- parameters can have multiple arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

function addTwoNumbers(a, b) {

	var result = a + b;
	alert(result);
}

addTwoNumbers(5, 10);

*what is the parameter?

A

the inputs of a, b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

function addTwoNumbers(a, b) {

	var result = a + b;
	alert(result);
}

addTwoNumbers(5, 10);

*what is the argument?

A

the inputs of 5, 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

variable scope

A
  • variables created within a function
  • these variables are limited to the function

Suppose you create a function:

function myFunction() {
   var x = 500

}

Now, if you simply wrote code to alert (x), nothing will happen because X was created within the function and limited to the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

global variable

A
  • variable created outside of a function.

- can be used anywhere in your code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

scripts tag

A
  • used to link other javascript pages together

- think external stylesheet for javascript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

javascript script tag

what does it look like?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

iteration

A

the process of looping code

sometimes iteration IS called loop or looping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

to use the javascript looping or iteration ability, we replace…

A

if with while

example:

var a = 1;

while (a >10) {

alert (a)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

infinite loop

A
  • the result of not incrementing or modifying an index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

steps to creating a loop using WHILE

A

1) set up the index
2) check the condition
3) increment the index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

for loop

A

simplifies the while loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

use the for loop:

var i = 1
while (i
A

for (var i=1; i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

do while loop

A

executes the loop before checking the condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

change to do while loop

var i = 1
while (i
A

var i = 1;

do {i++
} while ( i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

NaN

A

Not a number

what displays when javascript does not understand.

17
Q
var foo = 5;
var bar = 5;

alert ( foo + bar);

*what will display? why?

A

10

the values for foo and bar are numbers and the + represents adding

18
Q
var foo = "5";
var bar = "5";

alert ( foo + bar);

*what will display? why?

A

55

the two “5” represents character strings so “5” + “5” will CONCATONATE

19
Q
var foo = 5;
var bar = "5";

alert ( foo + bar);

*what will display? why?

A

55

if one is a string then that one “takes charge”

20
Q
var foo = 5;
var bar = "5";

alert ( foo * bar);

*what will display? why?

A

NaN

javascript will not understand a number multiple by a character string

21
Q

how would you convert the var a = “55” into a variable a being 55

A

using the Number function

var a = "55"
var newVariable = Number(a)

now newVariable is a variable that is = 55

22
Q

what javascript function would you use to check if a viable is not a number?

A

isNaN

^ is NOT a number

23
Q

what javascript function would you use to check if a viable is a number?

A

!isNan

^ is NOT NOT a number

24
Q

suppose you have a variable:

var a = “This is a”;

*How do you determine the # of character strings inside variable a

A

a.length

using the length property

25
Q

methods

A

functions but for character strings

26
Q

suppose you have a variable:

var a = “This is a”;

*How do you uppercase everything in a?

A

a.toUpperCase()

27
Q

suppose you have a variable:

var a = “This is a”;

*How do you convert all of a to lowercase?

A

a.toLowerCase()

28
Q
var a = "Hello";
var b = "hello";

are a and b the same?

A

NO

29
Q

Suppose you have:

var a = "Hello";
var b = "hello";

*how do you make a = b?

A

a.toLowerCase() == b.toLowerCase()

  • this will change both a and b to “hello”
  • or you can upper case in which case both a and bc will be “HELLO”
30
Q

suppose you have

var a = “We want something new”;

*how do you find the position of the world “something”?

A

var position = a.indexOf(“something”);

  • now position will be = 9
  • remember, the first letter/number is 0 while using indexing
  • in var a = “We want something new”; - W = 0, e =1, (white space) = 3, etc…
31
Q

if you use indexOf method and receive a -1, that means….

A

the string does not exist you are trying to index.

32
Q

what methods exist to break character strings up? (3)

A

1) .slice
2) .substring
3) .substr

33
Q

suppose you have:

var a = “Yet another variable”;

use slice to pull out “other” from a

A

var b = a.slice (6, 11)

34
Q
var a = "aaaaaa";
var b = "bbbbbb";

what is large, a or b?

A

a

because javascript looks at the first character and seems a is larger than b, it goes alphabetically

35
Q
var a = "aaaaaa";
var b = "Bbbbbb";

what is large, a or b?

A

B

javascript assumes letters that are capitalized are larger values.

36
Q

regular expressions

A
  • finds patters and expressions within character strings
  • used if you want to know is a string is a URL, if a string matches the basic requirements of an email address, or if a string has numbers, etc…
37
Q

regular expressions (2)

A

1) create expression

2) apply and ask if it matches