Vous êtes sur la page 1sur 4

Question

on JavaScript and PHP



Notes on marking.

The number of marks allocated do not always reflect the difficulty of the question. Some
easy questions are worth the same number of marks as much harder questions. This serves
to extend either ends of the distribution (since some marks are very easy to attain only
really weak candidates will get marks approaching zero, and since some are hard to attain
only very strong candidates will get marks approaching 100%).

Where there is only 1 mark per section this is a simple right or wrong answer.
Where there are 2 marks per section, 1 mark is awarded for a partially correct answer.

Answer ALL parts of this question [total marks available 15]

(1) Write a JavaScript function called sayHello that display a dialog containing the text
"Hello".
[1 mark]

BT (knowledge)

Answer:

function sayHello() {
alert("Hello")
}

(2) Write a single line of HTML that will reference a JavaScript file called myScript.js
[1 mark]


BT (knowledge)

Answer:

<script src = "myScript.js">


(3) Explain the difference between the following lines of JavaScript:

A = B;
A == B;
A === B;

[2 marks]
BT (knowledge / comprehension)

Answer:

A = B will assign the value of A to B



A == B will compare A to B, returning true if it is the same value and false if it
is not

A === B will also compare A to B but it will only return true if both the value
and the type are the same


(4) Write a single line of JavaScript that will create an array called days containing the
strings "Monday", "Tuesday" and "Wednesday".
[1 mark]

BT (knowledge)

Answer:

var days = ["Monday", "Tuesday", "Wednesday"]

(5) Write a single line of JavaScript that will return the lowest values of two numeric
variables a and b
[1 mark]

BT (knowledge)

Answer:

Math.min(a,b);


(6) What would be output by the following JavaScript fragment?

<p id="output"></p>
<script>
var x;
document.getElementById("output").innerHTML = x + typeof(x);
</script>

[2 marks]

BT (knowledge/application)

Answer:
undefinedundefined



(7) What would be output by the following JavaScript code fragment?

<p id="output1"></p>
<p id="output2"></p>
<script>
var x;
document.getElementById("output1").innerHTML = 0 == false;
document.getElementById("output2").innerHTML = 0 === false;
</script>


BT (knowledge/application)

Answer:

true

false

[1 mark]


(8) In PHP how do you access information submitted from a form using the GET method
[1 mark]
BT (knowledge)

Answer:
It is available in the $_GET[] array


(9) Write a single line of PHP that will create an array called $days that contains the strings
"Monday", "Tuesday" and "Wednesday"
[1 mark]
BT (knowledge/application)

Answer:

$days = array("Monday","Tuesday","Wednesday")


(10)
Write PHP code that will loop through the @days array declared in question 12,
output the information as follows:

Red = 255:0:0
Green = 0:255:0
Blue = 0:0:255

[2 marks]

BT (application)

Answer:

foreach($colour as $col => $rgb) {
echo $col . " = " . $rgb;
echo "<br>";
}

(11)
Write PHP code that will output "Good morning" if the time is earlier than 12.00,
"Good afternoon" if it is between 12.00 and 18.00 and "Good evening" if it is after 18.00.
[2 marks]

BT (application)

Answer:


$time = date("H");

if ($time < "12") {
echo "Good morning";
} elseif ($time >= "12" && time < "18" ) {
echo "Good afternoon";
} else {
echo "Good evening";
}
}

Vous aimerez peut-être aussi