Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Exam (elaborations) CS 10787

Rating
-
Sold
-
Pages
21
Grade
A+
Uploaded on
09-07-2024
Written in
2023/2024

1. Which of the following lines of JavaScript code will change the HTML inside of an element with the attribute id="myElement" to "CS 105"? A. ElementById(“myElement”).innerHTML = “CS 105”; B. html[“myElement”] = “CS 105”; C. html[“myElement”].innerHTML = “CS 105”; D. [“myElement”].innerHTML = “CS 105”; E. Element(“CS 105”); Explanation As part of doing MP3, you learned that the JavaScript code: ElementById( ___1____ ).innerHTML = ____2_____; ..changes the element in the HTML document which has an attribute id="____1____" to the contents of 2. The only option that follows this syntax is (A). Additionally, you specifically programmed this line of code as part of completing MP3. 2. Which term is not synonymous with the term JavaScript? A. ECMAScript B. JS C. Java D. All of the terms above are synonymous with JavaScript. Explanation In Lecture 4.2, you learned that JavaScript, JS, and ECMAScript are all correct terms for JavaScript. However, Java is a completely different language than JavaScript. Saying “Java” when referring to “JavaScript” is incorrect. 3. Given the array, var a = [20, 40, 60, 80, 100], which line of code accesses the value 40? A. a[0] B. a[1] C. a[2] D. a[3] E. a[i] Explanation When accessing elements inside an array, we access them by their index. The first index in every array is zero (0). Therefore a[0] == 20, a[1] == 40, a[2] == 60, and so forth. This question is looking for 40, which is contained in a[1]. CS 105: Sample Midterm Exam #1 Page 3 of 21 For the next two questions, consider the following code: 1 2 3 4 5 6 var x = 20; while (x 10) { print("Hello"); x *= 2; } 4. Assuming that the function print() has been defined that prints the value passed in as the parameter to it, how many times is “Hello” printed? A. 0 B. 1 C. 2 D. 3 E. Infinity (or at least until you kill the program) Explanation Line 1 initially sets our variable x to 20. Line 2 checks if x is less than 10. …is 20 less than 10? No. Since our conditional is false, we skip the code inside of the curly braces. Since there is nothing after Line 6, our program is finished. “Hello” is printed zero (0) times. 5. If the initial value of x (set on Line #1) is now 5 instead of 20, how many times is “Hello” printed? A. 0 B. 1 C. 2 D. 3 E. Infinity (or at least until you kill the program) Explanation Line 1 initially sets our variable x to 5. Line 2 checks if x is less than 10. …is 5 less than 10? Yes. Since our conditional is true, we run the code inside of the curly braces. Line 4 prints “Hello” Line 5 multiples x by 2. Since the old value was 5, the new value is now 5*2, so x = 10. Line 6 reaches the end of our loop, so the program checks Line 2 again. …is 10 less than 10? No. Since our conditional is false, we skip the code inside of the braces. Since there is nothing after Line 6, our program is finished. “Hello” is printed 1 time.

Show more Read less
Institution
CS 10787
Course
CS 10787










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CS 10787
Course
CS 10787

Document information

Uploaded on
July 9, 2024
Number of pages
21
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
leonardkinyua

Get to know the seller

Seller avatar
leonardkinyua Abraham Lincoln University, School Of Law
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
323
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions