Challenges Flashcards

Review and Practice

1
Q

Choose the numbers that are NOT present in this code’s output.
for(let i = 10; i <= 15; i++)
document.write(45 - i + “,”);
Select all that apply

44
34
24
23

A

44, 24, 23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
What is the output of this code?
var a=8;
var b=9;
a=(b%2)+a/(a%3);
document.write(a);
A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
What is the output of this code?
var arr = [5, 6, 8];
var str = (string)arr;
var bool = (boolean)str;
console.log(bool);

True
False
Error

A

Error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What will be alerted? 
function bar() {
  return foo;
  function foo() {} 
  var boo = '11';
}
alert(typeof bar());

undefined
function
string
number

A

Function

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

Fill in the blanks to change the content of the div to “Hi there”.

<div></div>

var d,a;
d=document.getElementById(‘ txt ‘);
a=document.createTextNode(“Hi there”);
d .appendChild( a );

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
What is the output of this code?
function changeNum(b) {
  b = 2;
}
var a = 3;
changeNum(a);
alert(a); 

Error
2
3
undefined

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
What is the output of this code?
for(var x = 0; x == x; x++) {
  if(x > 5 && x < 8) {
    document.write(x);
    break;
  }
}
A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
What is the output of this code?
function mult(x=10, y=2) {
  return x / y;
}
document.write(mult(30));
A

15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
What is the output of this code? 
if(10 > 9) {
  document.write("true");
}
else {
  document.write("false");
}  
false  
true  
True  
False
A

true

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

You can write JavaScript code inside HTML document.

A

True

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

What is the result of this code?
alert(console.log(“Solo”));

Prints “undefined” in alert box and prints “Solo” in Console.

Error

No output

A

Prints “undefined” in alert box and prints “Solo” in Console.

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

What is the output?
document.write(1==”1”);
false
true

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
What is the output of this code?
var nums = [1, 2, 3, 4, 5];
var str = "";
for(var i = 0; i < 5; i++) {
  str += nums[i] + " ";
  nums.unshift(1);
}
console.log(str);

1 1 2 3 4
5 4 3 2 1
1 1 1 1 1
1 2 3 4 5

A

1 1 1 1 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
What is the data type of variable x?
let x = true;  

undefined
number
string
boolean

A

boolean

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

What is the output of this code?
var a =”2”+”8”;
var b = a.replace(“2”,”3”);
alert(b);

A

38

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
What is the output of this code?
for(var x = 1; x > 0; x++) {
  if(x > 7) {
     alert(x);
     break;
  }
}
A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
What is the output of this code?
var a = 8;
a = a + a / (a % 3);
document.write(a);
A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
What will be alerted?
function prod(a,b,c=3) {
  x=a*b*c;
  return x;
}
result=prod(8,3,5);
alert(result);
A

120

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

This statement is used to specify a block of code that will be executed if a specified condition is true.

  • if
  • unless
  • or
  • else
A

If

20
Q
Fill in the blanks to make the whole code block a comment.  
/*   var a = 5;  
var b = 6;  
var sum = a+b;   */
A

True

21
Q
What is the output of this code?
var a = 5;
var b = a % 2;
a = a - b;
alert(a);
A

4

22
Q

Which choice is the largest number among the options?

Options:
Math.abs(16)  
Math.exp(16)  
2017  
Math.sqrt(16)
A

Math.exp(16)

23
Q
What is the output of this code? 
var a = "hello";
var b = 1;
var c = a + b;
alert(c + b);
A

hello11

24
Q

What will be alerted?

alert(“N”>”B”||”1”===1||”E”

A

True

25
Q

Fill in the blanks to output all the EVEN numbers in the range 50 to 120.

for  (var i=50; i<=  120  ;   
i+=  2  ) {  
  document.write(i);
}
A

True

26
Q

The slice() method of array prototype changes the original array.

A

False

27
Q
What is the output of this code?
var car = {
  color: 'green',
  wheels: 4,
  riding: false
};
car.riding =
  car.wheels === car['wheels'] ? true : false;
if(car.riding)
  console.log('ride');
else
  console.log('stop');
A

ride

28
Q

What is the output of this code?
var x = 8 % 4;
var res = (x >= 0)?”false”:”true”;
alert(res);

A

False

29
Q

Can you write JS code directly in an HTML file?

No, because JS code needs its own file.
No, because JS is never compatible with HTML.
Yes, by using the tag.
Yes, by using the tag.

A

Yes, by using the tag.

30
Q
What is the output of this code?
var a = 5;
var b = a * 5;
var c;
if (a > 2)
  c = a + b;
else
  c = b - a;
console.log(c);
A

30

31
Q

What is the output of this code?
let a, b;
[a, b = 6] = [2];
console.log(a + b);

Options:
6  
2  
8  
10
A

8

32
Q
What is the output of this code? 
var s1="sololearn";
var s2="solo"+"learn";
document.write(s1 == s2);
A

True

33
Q

What is the output of this code?
var numbers = [44, 55, 66, 12, 67, 89];
console.log(numbers[numbers.length]);

Options:
undefined  
67  
89  
12
A

Undefined

34
Q
Fill in the blank to output 3.  
var a=   9  ;  
var b = 5;
b++;
alert(a - b);
A

True

35
Q
What will be alerted?
var solo1 = [1, 2];
var solo2 = new Array(1, 2);
alert(typeof(solo1) + typeof(solo2));  
Options:
objectarray  
arrayobject  
arrayarray  
objectobject
A

objectobject

36
Q

What is the output of this code?
var i = 1;
for (; i < 24; i += 3) {}
alert (i);

A

25

37
Q

What is the output of this code?

<p><a>hi</a></p>

  var p=document.getElementById('p'); 
  var a=document.getElementById('a'); 
  var t=document.createTextNode('Hello');
  p.removeChild(a);
  p.appendChild(t);
Options:
Hello  
hi  
nothing  
a
A

Hello

38
Q

Fill in the blanks to output the value of x, if it is even.

var x = 8;  
if  (x  %  2 == 0) {  
  document.write(  x  );  
}
A

True

39
Q
What is the output of this code?
function*x() {
  var y = 8 - (yield 8);
  return y;
}
var u = x();
u.next().value;
console.log(`${u.next(1).value}`);  
Options
Error  
0  
16  
7
A

7

40
Q
What is the output of this code? 
var a=[3,17,35,51,89];
var b=a[3] % 9;
while (b < 11) {
   document.write(b);
   b++;
}
A

678910

41
Q

What is the output of this code?
for(var i=5; i<9; i++) {
console.log(9-i);
}

A

4321

42
Q

Do anonymous functions exist in JS?

A

Yes

43
Q
What is the output of this code?
var x=1;
for(;x<6;x+=2) {
  x=x*x;
}
alert(x);
A

11

44
Q

What is the output of this code?
alert(Math.round(5.6));

Options:
6
5

A

6

45
Q

Does global object window contain all variables as properties?

Options: 
No, only local variables.  
No, variables are not properties of the global object.  
No, only global variables.  
Yes, all variables.
A

No, only global variables.