JavaScript Flashcards

(58 cards)

1
Q

create a dialouge box that says “Hello from Treehouse”

A

alert(“Hello from Treehouse”);

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

print to the page “Welcome to JavaScript Basics”

A

document.write(“<h1> Welcome to JavaScript Basics </h1>”);

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

add JavaScript to an HTML document

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

link a scripts.js file to an html file

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

print a “Start program” message to the console

A

console.log(“Start program”);

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

create a dialogue box which displays the contents of the var message

A

alert(message);

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

escape the apostrophe in She’s a great programmer.

A

She's a great programmer. (backslash is above Shift on the US keyboard)

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

capture visitor’s input by storing prompt data in a visitorName variable

A

var visitorName = prompt(‘What is your name?’);

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

create a var message that combines the greeting ‘Hello’ with the visitor’s name (var name) and “Welcome”;

A

var message = “Hello “ + visitor + “. Welcome”;

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

concatenation operator

A

+=

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

create a variable fullName which combines firstName and lastName

A

var fullName = firstName + “ “ + lastName;

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

print to the console var message converted to upper case

A

console.log(message.toUpperCase());

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

what is an integer?

A

a whole number without a decimal point (5, 10, etc.)

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

convert var totalBadges = HTMLBadges + CSSBadges from string to numbers

A

var totalBadges = parseInt(HTMLBadges) + parseInt(CSSBadges);

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

function for converting a string with integers to numbers

A

parseInt();

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

convert ‘1.25’ to numbers

A

parseFloat(‘1.25’);

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

round 4.5 to the nearest integer using a math method

A

Math.round(4.5);

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

erase all the data from the console

A

clear();

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

create a random number from 1 to 6 using Math.random

A

Math.floor(Math.random () * 6) +1;

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

create a random number within a range from bottomNumber to topNumber

A

var randomNumber = Math.floor(Math.randon() * (topNumber - bottomNumber +1)) + bottomNumber;

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

equality operator

A

===

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

write a conditional statement that gives to alternatives 1) Yes, that’s right 2) Sorry, that’s wrong to a question ‘What programming language is the name of a gem?

A

var message = prompt(‘What programming language is the name of a gem?’);

if (answer.toUpperCase === ‘RUBY’) {
	document.write(<p>“That’s right” </p>)
} else {
	document.write(<p> Sorry. That’s wrong. </p>)
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

single line comment

A

// This is a single line comment.

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

multiple line comment

A
/* This is a multiple line code . . . 
. . . . */
25
and operator
&& (two ampersands)
26
or operator
|| (two pipes, just above shift)
27
create a sayHi function with an alert that says Hi
``` function sayHi () { alert('Hi'); } ```
28
call the sayHi function
sayHi();
29
Which JavaScript keyword is used to send back a value from a function?
return
30
if var age < 18 display an error message "You are too young to use this program".
``` if (age < 18) { throw new Error("You are too young to use this program"); } ```
31
Finish the code below, so that the function returns the message variable: ``` function greeting( name ) { var message = "Hello " + name; ``` }
``` function greeting( name ) { var message = "Hello " + name; return message; } ```
32
create an array myShopping and add 3 items to the lisst
var myShopping = ['milk', 'bread', 'butter'];
33
print the first item of the myShopping array to the console
console.log(myShopping [0] );
34
create a for loop that prints numbers from 1 to 10;
for (i=1, i<11, +=1) { console.log(i); }
35
add numbers 7, 8 and 9 to the numbers array using the push method
numbers.push(7, 8, 9);
36
add 5, 11, 12 to the beginning of the numbers array
numbers.unshift(5, 11, 12);
37
Where do you normally put the js script tags inside an html document?
Just before the closing body tag
38
print out the whole of myShopping array
printList (myShopping);
39
remove the last item from the myShopping array
myShopping.pop( );
40
remove the first item from the myShopping array
myShopping.shift( );
41
find out how many items are inside the myShopping array
myShopping.length
42
display the contents of the myShopping array inside the console
myShopping
43
display the last used command in the console
press the up arrow on the keyboard
44
remove the first item from the array myShopping and place it in the buyLater variable
var buyLater = myShopping.shift( );
45
iterate through the students array and print the values to the console
var students = [‘Mike’, ‘Kate’, ‘Jane’, ‘Louis’]; for (var i = 0; i < students.length; +=1) { console.log(students[i]); }
46
Use a while loop to iterate through the values in the temperatures array var temperatures = [100,90,99,80,70,65,30,10];
var temperatures = [100,90,99,80,70,65,30,10]; var i = 0; while (i < temperatures.length) { console.log(temperatures[i]); i += 1; }
47
Use a for loop to iterate through the values in the temperatures array var temperatures = [100,90,99,80,70,65,30,10];
for (var i = 0; i < temperatures.length; i+=1) { console.log(temperatures[i]); }
48
create a daysString variable that converts the daysInWeek array into a string with values separated by comma
var daysString = daysInWeek.join( ‘, ‘ );
49
create a new array allStudents that joins currentStudents with newStudents arrays
var allStudents = currentStudents.concat(newStudents);
50
save the index position of Apple in the new variable position var fruits = ['Apple', 'Orange', 'Grapefruit'];
var position = fruit.indexOf(‘Apple’);
51
access the age property of the person object with an alert window
``` var person = { name: 'David', age: 24 } ``` alert(person.age);
52
change the name property of the person object to 'Bobby'
``` var person = { name: 'David', age: 24 } ``` person.name = 'Bobby';
53
add a new country property to the person object set to Brazil
``` var person = { name: 'David', age: 24 } ``` person.country = 'Brazil';
54
create a function that prints a message inside an html div
``` function print(message) { var div = document.getElementbyId(‘output’); div.neerHTML = message; } ```
55
loop through the keys of the student object and print them to the console
var student = { name: “Dave”, grades: [80, 85, 90, 95] }; for ( var propName in student ) { console.log(propName); }
56
loop through the values of the student object and print them to the console
var student = { name: “Dave”, grades: [80, 85, 90, 95] }; for ( var propName in student ) { console.log(student[propName]); }
57
print multiple variables in the console and separate them with a colon
console.log(variable1, ': ', variable2);
58
what does JSON stand for?
JavaScript Object Notation