Storing and Tracking Information with Variables Flashcards
- Create a variable named myName.
- Assign your name (as a string) to the myName variable.
var myName = “Randy”;
Variables can only contain what characters?
- letters
- numbers
- $
- _
Finish the code below to create a variable named shipsLeft containing the number 10.
_____ shipsLeft = 10;
var
Complete the code below to create a variable named timeRemaining (don’t put anything in the variable).
var _____ ;
timeRemaining
What creates a variable named playerName and stores the name “Shawna” in it?
var playerName = “Shawna”;
- 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.
var player = “Jasmine”;
document.write(player);
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!’;
\
- 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.
var answer = prompt("What day is it?"); document.write(answer)
- 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”.
var firstName = “Randy”;
var lastName = “Reyes”;
var fullName = firstName + “ “ + lastName;
Complete the code below to create a new variable named message containing the string “JavaScript”
var _____ = _____ + ‘Script’;
message, “Java”
What tells a browser to open a dialog box for collecting a response with the message “Type your name” in it?
prompt(‘Type your name’);
The process of combining one or more strings is called:
concatenation
What produces the same result as this code:
var greeting = ‘Hi’; greeting = greeting + ‘ there!’;
var greeting = ‘Hi’;
greeting += ‘ there!’;
- 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
var id = "23188xtr"; var lastName = "Smith";
var userName = id.toUpperCase(); userName += "#" + lastName.toUpperCase();
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.”
alert( message.toLowerCase() );