CPSC 1045 Midterm Exam 1- Solved
Consider the following HTML paragraph
<p id="paragraph1">Here is a paragraph in English.</p>
Match each piece of the HTML element to its descriptor.
# opening tag
# attribute value
# text content
# attribute name
# closing tag
1.<p>
2.</p>
3.id
4."paragraph1"
5.Here is a paragraph in English. - ANSWER-1
4
5
3
2
Everything inside the
______
element is shown to the user inside the main browser window. Before this element we
will often see a
______
element that contains information about the page rather than information shown on the
page. This element usually contains a <title> tag. - ANSWER-body
head
For each scenario described select the appropriate input/output programming structure
you should use to complete the task.
# If a programming problem asks you to get the user input from a text field, you would
use...
# If a programming problem asks you to output some text to a textfield on the webpage,
you would use...
# If a programming problem asks you to output some value part way through your
program for debugging purposes, you would use...
# If a programming problem asks you to output some text to the HTML webpage (in say
a div or a paragraph), you would use..
1.let val = document.getElementById("someID").value;
2.document.getElementById("someID").innerHTML = "some text";
, 3.document.getElementById("someID").value = "some text";
4.console.log(value); - ANSWER-1
3
4
2
function doubleOrTriple( x ) {
if(typeof(x) !== "number"){
return NaN;
} if(50 <= x){
return x*2;
} else {
return x*3;
}
}
What value is returned by each of the following function calls?
1. doubleOrTriple(40)
2. doubleOrTriple(doubleOrTriple(40)) - ANSWER-1. 120
2. 240
function hypotenuse(a,b){
return Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
};
let a = 3;
let b = 4;
console.log(hypotenuse(a,b));
What is printed to the console? - ANSWER-5
function stringTooLong(str, length){
if(typeof(str) != "string" || isNaN(length)){
return false;
}else if(str.length() <= length){
return false;
}else{
return true;
}
}
Given the function above, in the first blank write a function call that will cause this
function to return true.
In the second blank write a function call that will cause this function to return false. -
ANSWER-stringTooLong("Hello", 1)
stringTooLong("Hello", 10)
Consider the following HTML paragraph
<p id="paragraph1">Here is a paragraph in English.</p>
Match each piece of the HTML element to its descriptor.
# opening tag
# attribute value
# text content
# attribute name
# closing tag
1.<p>
2.</p>
3.id
4."paragraph1"
5.Here is a paragraph in English. - ANSWER-1
4
5
3
2
Everything inside the
______
element is shown to the user inside the main browser window. Before this element we
will often see a
______
element that contains information about the page rather than information shown on the
page. This element usually contains a <title> tag. - ANSWER-body
head
For each scenario described select the appropriate input/output programming structure
you should use to complete the task.
# If a programming problem asks you to get the user input from a text field, you would
use...
# If a programming problem asks you to output some text to a textfield on the webpage,
you would use...
# If a programming problem asks you to output some value part way through your
program for debugging purposes, you would use...
# If a programming problem asks you to output some text to the HTML webpage (in say
a div or a paragraph), you would use..
1.let val = document.getElementById("someID").value;
2.document.getElementById("someID").innerHTML = "some text";
, 3.document.getElementById("someID").value = "some text";
4.console.log(value); - ANSWER-1
3
4
2
function doubleOrTriple( x ) {
if(typeof(x) !== "number"){
return NaN;
} if(50 <= x){
return x*2;
} else {
return x*3;
}
}
What value is returned by each of the following function calls?
1. doubleOrTriple(40)
2. doubleOrTriple(doubleOrTriple(40)) - ANSWER-1. 120
2. 240
function hypotenuse(a,b){
return Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
};
let a = 3;
let b = 4;
console.log(hypotenuse(a,b));
What is printed to the console? - ANSWER-5
function stringTooLong(str, length){
if(typeof(str) != "string" || isNaN(length)){
return false;
}else if(str.length() <= length){
return false;
}else{
return true;
}
}
Given the function above, in the first blank write a function call that will cause this
function to return true.
In the second blank write a function call that will cause this function to return false. -
ANSWER-stringTooLong("Hello", 1)
stringTooLong("Hello", 10)