Question: For this lab, you will use a single HTML file, lab-3.html. 1. On your personal computer, open up Visual Studio Code and create a new
For this lab, you will use a single HTML file, lab-3.html. 1. On your personal computer, open up Visual Studio Code and create a new file in your called lab-3.html. 2. Modify lab-3.html to include an HTML div element within the body element. 3. Add a script element referencing lab-3.js just before the body close element. 4. Save your changes to your lab-3.html file. lab-3.js For this lab, you will use the JavaScript source file lab-3.js. 1. On your personal computer, open Atom and create a new file in your 111/p1 folder called lab-3.js. 2. Add a function sumOddInts that accepts a positive integer n and returns the sum of the odd numbers from 1 to n. Your function must: i. Use one of the loop structures we have learned in class. ii. Test to make sure the number is greater than or equal to 0 using a conditional (you may be able to avoid the conditional, if you write the loop right.)
iii. For numbers less than 0, return 0. 3. Test your function by copying the function to the Chrome Console and calling the function with various values, including a negative value and zero. You can include your function call tests within your JavaScript file. 4. Update lab-3.js to prompt the user for a number. 5. Call sumOddInts with the user entered number. Do NOT modify sumOddInts. 6. Use querySelector to reference the HTML div element. 7. Use innerHTML property to set the display contents of the div element with the results of the call to sumOddInts
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
