wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Khan Academy Javascript

Total questions: 40

Worksheet time: 37mins

Name
Class
Date
1.

The body of a function definition is contained within a set of ______________.

a)

parentheses

b)

curly braces

c)

rectangle brackets

d)

angle brackets

2.
In JavaScript, you should include a semi-colon at the end of each statement.
a)
yes
b)
no
3.

Perform the operation on operands of different data types given that a = 4 , b = happy , c= people, d = 9 , e = memories


Solve: b + c

a)

happy people

b)

people happy

c)

happy memories

d)

happy plus

4.
What surrounds a string?
a)
Quotations
b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
5.

Identify the data type of the following variable?

streetNumber = "56"

a)

String

b)

Number

c)

Integer

d)

Character

6.

Determine what result each expression yields if it is True or False. Given that x= 8 and y= 16.


!(x=8)

a)

True

b)

False

7.
Which command colors the background of your canvas?
a)
background 
b)
endShape
c)
var = color
d)
fill
8.
Javascript is case-sensitive
a)
True
b)
False
9.

Used to store data keywords.

Uses var keyword in declaring ________.

a)

variance

b)

various

c)

variety

d)

variable

10.

An __________ is used to assign values to variables.

a)

Subtraction Sign -

b)

Equal Sign =

c)

Addition Sign +

d)

Parenthesis ()

11.

var faceSize = 300;
var eyeSize = 40;
Which one is the correct way to relate face and eye size?

a)

faceSize = 2/15 * eyeSize

b)

eyeSize = 2/15 * faceSize

c)

faceSize = 3/4 * eyeSize;

d)

eyeSize = 3/4 * faceSize;

12.
What command draws a rectangle?
a)
rec (10, 20, 100, 200);
b)
rect (10, 20, 100, 200)
c)
rect (10, 20, 100, 200);
d)
ellipse (10, 20, 40, 40)
13.

Which of the following is an advantage of using local variables?

a)

They allow the variable to be used throughout the whole program.

b)

They allow variable identifiers to be reused each time.

c)

They are easier to program than global variables.

d)

A wider range of data types can be used.

14.
What command removes the outlines from shapes?
a)
noOutline ();
b)
noColor();
c)
noBorder();
d)
noStroke ();
15.
What command colors a shape?
a)
color (43, 255, 0);
b)
bucket (43, 255, 0);
c)
fill (43, 255, 0);
d)
bucket (43, 255, 0);
16.
Any code that is within the following draw function:
draw = function(){
......
}
a)
Will be performed twice
b)
Will not be performed
c)
Will be performed once
d)
Will be repeated over and over again
17.
Is JavaScript exactly the same as Java?
a)
No
b)
Yes
18.

The return statement does two things:

a)

gives a value back to whoever called it and immediately exits the function.

b)

calling the function and calculate the numbers.

c)

combining the expressions and returning the values.

d)

reusable and flexible

19.

Which of these is a loop?

a)

if(x<10)

b)

while(x<10)

c)

var x=10;

d)

text(x,10;10)

20.

Which of the following will decrease the value of x?

a)

x--;

b)

x-1;

c)

x=x;

d)

x=-x;

21.

Greater than or equal to

a)

> or =

b)

> || =

c)

>=

d)

<=

22.

Given the following code, which is considered the parameters of the function


function myFunction(a, b, c) {

var x = a + b + c;

}

a)

x

b)

a

c)

b

d)

c

23.

Given the following code, what is the final value of x?


var x = 0;

function myXFunction() {

x = x + 10;

}

x = x + 1;

a)

11

b)

0

c)

10

d)

1

24.

What is the syntax for creating a function in JavaScript named as Geekfunc?

a)

A) function = Geekfunc()

b)

B) function Geekfunc()

c)

C) function := Geekfunc()

d)

D) function : Geekfunc()

25.

Which of the following operator is used for the Assignment Operator?

a)

==

b)

!

c)

=

d)

+

26.

Allow functions to accept input and perform a task using the inputs.

a)

Global Namespace

b)

Parameter

c)

Blocks

27.

What is the symbol used for the INCREMENT operator in JS?

a)

+

b)

++

c)

=

d)

==

28.

Since JS functions allow reusability of code, how many times do written codes need too be DEFINED?

a)

TWICE

b)

THRICE

c)

AS MANY AS POSSIBLE

d)

ONCE

29.

Functions that contain ____________ MUST be called as part of a larger statement that is usually an assignment or output.

a)

return data

b)

local variables

c)

parameters

d)

none of the above

30.

Which is the correct way to write a comment in JavaScript?

a)

(#...#)

b)

(!...!)

c)

{{.....}}

d)

//....

31.

The point (0, 0) on the Khan Academy JS canvas is located at the

a)

top right corner

b)

top left corner

c)

bottom right corner

d)

bottom left corner

32.

To draw an oval with its centre at the origin, width 100, height 150, filled with RED colour, which one is correct?

a)

fill (255, 0, 0); ellipse(0, 0, 100, 150);

b)

fill (0, 0, 0); ellipse (0, 0, 150, 100);

c)

fill (255, 255, 255); ellipse (100, 150, 0, 0);

d)

ellipse (0, 0, 100, 150);

33.

How many values (numbers) are needed for the triangle command?

a)

3

b)

12

c)

4

d)

6

34.

Javascript can:

a)

Interact with HTML

b)

Check or validate user input

c)

Can make your web pages dynamic

d)

All of the above

35.
You've defined a function named calcAge that takes three parameters (day/month/year) and returns a value. How do you call that function and store the resulting value?
a)
var calcAge(24, 6, 1984);
b)
var age = calcAge(24, 6, 1984);
c)
var age = calcAge(24/6/1984);
d)
var age = calcAge = 24, 6, 1984;
36.

text("hello", 30, height);

a)

"hello" text is at the top of the screen.

b)

"hello" text is at the lowest part of the screen.

c)

"hello" text is in the middle of the screen.

37.

Which command is following the mouse pointer?

a)

text(message, 100, 100);

b)

text(message, mouseX, mouseY);

c)

text(message, mouseY, mouseX);

d)

text(message, x, y);

38.

Which two arguments represent the current position of the cursor?

a)

cursorX & cursorY

b)

mouseX & mouseY

c)

pointerX & pointerY

d)

crosshairX & crosshairY

39.

Let's say we have a program that draws an ice cream cone (a triangle) with two scoops of ice cream (two ellipses) on top of it. The second scoop is slightly smaller than the first, and we have two variables, scoop1 and scoop2, to keep track of the scoop sizes:

var scoop1 = 40; 

var scoop2 = 30; 

triangle(200, 250, 180, 200, 220, 200); 

ellipse(200, 180, scoop1, scoop1); 

ellipse(200, 145, scoop2, scoop2); 

If we want to make scoop2 dependent on scoop1, so that scoop2 is always 10 pixels smaller than scoop1, what expression should we store in the scoop2 variable?

a)

scoop1 * (3/4)

b)

scoop1 - 10

c)

scoop1 + 10

d)

30

40.

Create a function that draws a rectangle using line function in javascript language.

4 lines