Storing and Tracking Information with Variables Flashcards

1
Q
  • Create a variable named myName.
  • Assign your name (as a string) to the myName variable.
A

var myName = “Randy”;

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

Variables can only contain what characters?

A
  • letters
  • numbers
  • $
  • _
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Finish the code below to create a variable named shipsLeft containing the number 10.

_____ shipsLeft = 10;

A

var

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

Complete the code below to create a variable named timeRemaining (don’t put anything in the variable).

var _____ ;

A

timeRemaining

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

What creates a variable named playerName and stores the name “Shawna” in it?

A

var playerName = “Shawna”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • Create a player variable with the string ‘Jasmine’ in it.
  • Use the document.write() function to print the contents of the player variable to the page.
A

var player = “Jasmine”;

document.write(player);

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

In the code below there are too many single quote marks. Add the character that “escapes” the second single quote and tells the browser to treat that quote as just a regular character:

var text = ‘She_____’s the best!’;

A

\

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • Create a variable named answer.
  • Use the prompt() method to ask the user “What day is it?” and store the result in the answervariable.
  • Use the document.write() method to write the variable answer to the page.
A
var answer = prompt("What day is it?");
document.write(answer)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • Create a variable named firstName and put your first name in the variable.
  • Create another variable named lastName and put your last name in it.
  • Create a variable named fullName that combines both the first and last name variables to create a string like “Mary Jones”.
A

var firstName = “Randy”;

var lastName = “Reyes”;

var fullName = firstName + “ “ + lastName;

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

Complete the code below to create a new variable named message containing the string “JavaScript”

var _____ = _____ + ‘Script’;

A

message, “Java”

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

What tells a browser to open a dialog box for collecting a response with the message “Type your name” in it?

A

prompt(‘Type your name’);

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

The process of combining one or more strings is called:

A

concatenation

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

What produces the same result as this code:

var greeting = ‘Hi’; greeting = greeting + ‘ there!’;

A

var greeting = ‘Hi’;

greeting += ‘ there!’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  • Assign an all uppercase version of the id variable to the userName variable.
  • Complete the assignment to the userName variable by adding a # symbol followed by an all uppercase version of the lastName variable. In other words, using string concatenation so that the final value of userName is “23188XTR#SMITH”.
var id = "23188xtr";
var lastName = "Smith";

var userName

A
var id = "23188xtr";
var lastName = "Smith";
var userName = id.toUpperCase();
userName += "#" + lastName.toUpperCase();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Given the following code, what statement opens an alert dialog with the contents of the variable message in all lowercase:

var message = “Kenneth and Andrew love to play Uno.”

A

alert( message.toLowerCase() );

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

Complete the code below to store the value 100 in the variable named score

var score = _____

A

100