wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

COM10.3.2

Total questions: 20

Worksheet time: 14mins

Name
Class
Date
1.
Strings can be treated as arrays of characters.
a)
True
b)
False
2.

For string symbol + means........................

a)

addition

b)

swapp

c)

concatenation

d)

multiplication

3.

index of a string begins with

a)

1

b)

0

c)

a

d)

-1

4.

let string = "foo"

How to determine the length of the string?

(a)  

5.

let string = "The cat is black"

How to find the index/position of "cat" in the string

(a)  

6.

let string = "The black cat is black"

How to find the LAST index/position of "black" in the string

(a)  

7.

let string = "Milk, chocolate, cookies"

How to extract a new string "chocolate, cookies" from the first string

(a)  

8.

let string = "Milk, chocolate, cookies"

How to figure out what character is on the 3rd position of the string?

(a)  

9.

let string = "Milk, chocolate, cookies"

How to convert the string to upper case?

(a)  

10.

let string = "Milk, chocolate, cookies"

How to convert the string to lower case?

(a)  

11.

let string = " Hello World! "

How to trim the whitespaces around "Hello World!" ?

(a)  

12.

String txt = "Hello World";

alert(txt.toUpperCase());


Choose the correct output.

a)

"HELLO WORLD"

b)

HELLO WORLD

c)

Hello world

d)

Hello World

13.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

14.

Choose most appropriate purpose of trim() method in String?

a)

to remove white spaces

b)

to get a substring of the string

c)

to cut String at desired index

d)

to remove extra white spaces from start and end of String

15.

What is the output of the given snippet?

a)

Hello

b)

,

c)

true

d)

false

16.

What does the following code log?

a)

-1

b)

6

c)

7

d)

NaN

17.

What does str.charAt(1) return for the string str = "Hello"?

a)

"H"

b)

"e"

c)

'l'

d)

undefined

18.

var len = "jump it!".length;


What is the value of len?

a)

8

b)

7

c)

9

d)

6

e)

This code does not compile.

19.

var s = "whatever".substring(1,4);


What is the value of s?

a)

"hate"

b)

"hat"

c)

"whate"

d)

"what"

e)

StringIndexOutOfBoundsException

20.

var p = "Go Paw Patrol!".indexOf("p");


What is the value of p? (Case matters)

a)

0

b)

4

c)

3

d)

-1

e)

This code will not compile.