Search Header Logo
Strings

Strings

Assessment

Presentation

Computers

9th - 12th Grade

Practice Problem

Medium

Created by

J. Moore

Used 3+ times

FREE Resource

9 Slides • 12 Questions

1

Storing Strings

media

Based on Kahn Academy and Daily Videos

2

media

When we're making a program, we often want to store sequences of letters, like storing “easy” as a game's difficulty level. In programming lingo, we call each letter a character and we call the sequence a string.

3

A string can contain any number of characters, including none at all, and those characters can be letters, numbers, or symbols.

Notice how each string is surrounded by double quotes on either side. If you don’t put any quotes around a string, JavaScript will get confused.

4

Open Ended

Question image

Tell me what is wrong with these variables?

5

Multiple Select

Which of these are valid lines of JavaScript to store a string?

Choose all answers that apply:

1

var age = "35";

2

var greeting = "Ahoy, matey;

3

var empty = " ";

4

var nickname = Polly";

5

var title = "I, Robot";

6

Explanation

Several of the strings are invalid as they do not have a quote on both sides:

  • var nickname = Polly";

  • var greeting = "Ahoy, matey;

  • var store = BotsRUs;

The rest of the strings are valid, as they are fully quoted and are made up of letters, numbers, spaces, and symbols.

7

Pseudocode for strings

What's pseudocode?

Pseudocode is a language that represents programming concepts generally but doesn't actually run anywhere. Pseudocode is useful for planning programs and for thinking about code independently of a specific programming language. The AP CSP exam uses pseudocode for all the questions, so we use pseudocode for our exercises here.

8

Pseudocode for strings

What's pseudocode?

This pseudocode represents storing a string:

a ← "STRING"

Whenever you see that pseudocode, it means that the variable a (or whatever it's called) is storing the string inside the double quotes.

For example, you might see pseudocode like this:

difficulty ← "medium"

That means the variable difficulty is storing the string "medium".

9

Multiple Choice

What is the pseudocode equivalent of this JavaScript?

var hair = "curly";

1

hair = "curly"

2

hair ← curly

3

hair ← "curly"

4

hair = curly

10

Explanation

hair = curly

This pseudocode is using = instead of ←. In the pseudocode used here (and on the AP CSP exam), ← represents variable assignment. In addition, this pseudocode is missing quotation marks around the string value.

hair ← curly

This pseudocode is missing quotation marks around the string value.

hair = "curly"

This pseudocode is using = instead of ←. In the pseudocode used here (and on the AP CSP exam), ← represents variable assignment.

11

Multiple Choice

What is the pseudocode equivalent of this JavaScript?

var password = "2278";

1

password = 2278

2

password = "2278"

3

password ← 2278

4

password ← "2278"

12

Explanation

password = 2278

This pseudocode is using = instead of ←. In the pseudocode used here (and on the AP CSP exam), ← represents variable assignment. In addition, this pseudocode is missing quotation marks around the string value.

password = "2278"

This pseudocode is using = instead of ←. In the pseudocode used here (and on the AP CSP exam), ← represents variable assignment.

password ← 2278

This pseudocode is missing quotation marks around the string value.

13

Fill in the Blanks

media image

Type answer...

14

media

The following variable assignments are from an online music app.

Identify which variables store numbers and which store strings:

15

Multiple Choice

title ← "I am a rock"

1

String

2

Number

16

Multiple Choice

minutes ← 2

1

String

2

Number

17

Multiple Choice

seconds ← 50

1

String

2

Number

18

Multiple Choice

artist ← "Simon & Garfunkel"

1

String

2

Number

19

Multiple Choice

recorded ← "Dec 14, 1965"

1

String

2

Number

20

Multiple Select

Question image

Google Maps lets users search for anything in the world:

The code to display the map and search results relies on many variables.

Which of these variables are storing a string data type?

👁️Note that there may be multiple answers to this question.

Choose all answers that apply: Choose all answers that apply:

1

city ← "Beverly Hills"

2

temp ← 63

3

weather ← "Partly Cloudy"

4

state ← "CA"

5

searchQuery ← "90210"

21

Multiple Choice

Isabel is programming an app called Plantwatch, which lets users monitor the health of their plants.

Which variable would she most likely use a string data type for?

Choose 1 answer:

1

species: The name of the plant species

2

numLeaves: The number of leaves on the plant

3

moisture: The percentage of water in the soil

4

acidity: The pH level of the soil

5

height: The height of the plant in centimeters

Storing Strings

media

Based on Kahn Academy and Daily Videos

Show answer

Auto Play

Slide 1 / 21

SLIDE