April 19, 2024

JavaScript Boolean Conditions

 

This question tests your knowledge of using Boolean conditions in conjunction with an if else statement.

JavaScript uses Unicode values of characters for comparison of strings. The value of 'A' is 65, 'Z' is 90 and 'a' is 97. The interpreter will compare the initial characters of the two strings; if each compared character is different the interpeter will be able to return true or false, otherwise it moves along and checks the next pair of characters and so on.

Q5.
i)
Complete this snippet of code by supplying a Boolean condition so that the message
Antelope is before Zebra
is displayed.

var a = 'Antelope';
var b ='Zebra';
if ---- code omitted ----
{
  document.write('Antelope is before Zebra' + '<br>');
}
else
{
  document.write('Zebra is before Antelope' + '<br>');
}

ii)
Complete this snippet of code by supplying a Boolean condition so that the message
antelope is before Zebra
is displayed.

var a = 'antelope';
var b ='Zebra';
if ---- code omitted ----
{
  document.write('antelope is before Zebra' + '<br>');
}
else
{
  document.write('Zebra is before antelope' + '<br>');
}

Link to answer.

 

Next page » A password problem

Previous page « Numbers

 

 

 

 

 

 

 

Up to top of page