CPSC 1045 Midterm Exam 1 - Solved: HTML, JavaScript, and Programming Concepts, Exams of Advanced Education

A comprehensive set of solved exercises and questions covering fundamental concepts in html, javascript, and programming. It includes examples of html elements, javascript functions, and programming structures, along with explanations and solutions. Ideal for students studying introductory programming and web development, offering a valuable resource for understanding key concepts and practicing problem-solving skills.

Typology: Exams

2024/2025

Available from 03/08/2025

Examproff
Examproff 🇺🇸

3

(2)

8.3K documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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";
pf3
pf4
pf5
pf8

Partial preview of the text

Download CPSC 1045 Midterm Exam 1 - Solved: HTML, JavaScript, and Programming Concepts and more Exams Advanced Education in PDF only on Docsity!

CPSC 1045 Midterm Exam 1- Solved

Consider the following HTML paragraph

Here is a paragraph in English.

Match each piece of the HTML element to its descriptor. # opening tag # attribute value # text content # attribute name # closing tag 1.

2.

3.id 4."paragraph1" 5.Here is a paragraph in English. - ANSWER- 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 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- 3 4 2 function doubleOrTriple( x ) { if(typeof(x) !== "number"){ return NaN; } if(50 <= x){ return x2; } else { return x3; } } What value is returned by each of the following function calls?

  1. doubleOrTriple(40)
  2. doubleOrTriple(doubleOrTriple(40)) - ANSWER-1. 120
  3. 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- 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)
  1. c(10); - ANSWER-1. 27
  2. 23
  3. 25 Match each definition to its corresponding term.

A variable that is defined inside a function that only exists when the function executes.

When we call a function by its name and brackets with parameters to make it

execute/run.

The final result that is given back to us by a function.

Generic place holders representing the input a function needs to solve a problem.

1.Function invocation 2.Parameters 3.Return value 4.Local variable 5.Global variable - ANSWER- 1 3 2 Match each programming statement to its correct output 8 + "8" NaN == NaN 8 + 8 10 - "a" "abc" <= "abd" typeof 5 1.number 2.true 3.false 4."88"

6.NaN - ANSWER- 3 5 6 2 1 Match each term to its description

#is a keyword/symbol used to combine, modify, or compare one or more expressions #a storage container whose type changes depending on what is being stored #a special type of number that indicates a result is not a valid number #the basic building blocks of JavaScript, includes strings, booleans, and numbers 1.Operator 2.Primitive type 3.Variable 4.NaN - ANSWER- 3 4 2 Match each term with the responsibility it manages in creating a website.

Is responsible for making the webpage dynamic and giving it functionality.

Is responsible for give the webpage content and structure.

Is responsible for modifying the appearance of a webpage.

1.HTML 2.CSS 3.JavaScript - ANSWER- 1 2 Order the operators in terms of highest precedence to lowest precedence. The operator that is evaluated (simplified) first should have a 1 next to it, and the operator evaluated last should have a 6 next to it.

  1. >=
  2. +=
  3. &&
  4. ||
  5. () - ANSWER-

Adobe Reader - ANSWER-Google Chrome There are three steps involved in getting the webpage to trigger some JavaScript code. Together these steps are known as event handling. Places these steps in the correct order that they should be done by the programmer.

  1. Select the HTML element(s) you want the script to respond to
  2. State the code you want to run when the event occurs.
  3. Indicate which event on the selected element(s) will trigger the response. - ANSWER- 1 3 2 Typical website behavior waits for the user to do something (to take an action), and then executes some JavaScript in response. This type of action/response behavior is called what? The Event Driven Programming Model The Procedural Programming Model The Task Response Programming Model The Client Server Programming Model The Object Oriented Programming Model - ANSWER-The Event Driven Programming Model What does the following expression evaluates to? 1 + 1 === "2" && 10 * 10 > 50 || 5 % 3 == "15" - ANSWER-false When creating a webpage you add tags to the contents of the page (known as markup). These tags provide extra meaning and structure. What kind of markup is used to describe both headings and paragraphs? Element Structural Semantic Tag - ANSWER-Structural Which of the following statements best describes the purpose of the following function? function evaluator(value, type){ return typeof(value) === type; } The function does nothing. The function identifies if the two parameters are equal. The function identifies if the type of the first parameter is the second parameter.

The function determines if the two parameters have the same type. - ANSWER-The function identifies if the type of the first parameter is the second parameter. Write the traditional DOM event handler (not the HTML event handler or DOM event listener) to make it so that when the button

called btn in the code below, is clicked the sayHello function executes. let btn = document.getElementById("mainBtn"); function sayHello(){ alert("Hello!"); } - ANSWER-btn.onclick = sayHello;