Question: I need help with question number 7 and 8, if possible please revise my code for the questions. Thank you! 3 Go to the bc_keys.js
I need help with question number 7 and 8, if possible please revise my code for the questions. Thank you!
3
Go to the bc_keys.js file in your editor. Add event listeners to run the findKeyWords() and makeKeyStyles() functions when the page is loaded.
4
Create the findKeyWords() function to locate the keywords from the document and generate the keyword list. Within the findKeyWords() function, perform the tasks described in steps 5 through 10.
5
Create an aside element with the ID keywords and containing an h1 heading with the text Keyword List.
6
Create an ol element and append it to the keywords aside element.
7
Next, generate the list of keywords and add IDs to each keyword entry in the source article. Create an object collection named keyWordElems referencing all dfnelements within the doc article (Hint: Use the querySelectorAll() method.) Create an array named keyWords with a length equal to the length of the keyWordElems collection. Add a for loop that loops through all the items in the keyWordElems object collection, and for each item do the following:
Set the value of each item in the keyWords array to the text of the corresponding item in the keyWordElems object collection.
Next, set the ID of the current item in the keyWords array. However, the ID cannot contain blank spaces. Norene has supplied you with the replaceWS() function to replace blank spaces with the _ character. Call the replaceWS() function with the current keyword as the parameter value and store the value returned by the function in the linkID variable.
Set the ID of the current item in the keyWordElems object collection to keyword_linkID where linkID is the value of the linkID variable.
8
Sort the keyWords array in alphabetical order.
my JS:
"use strict";
/*
New Perspectives on HTML5, CSS3 and JavaScript 6th Edition
Tutorial 12
Review Assignment
Author:
Date:
Filename: bc_keys.js
Functions
=========
findKeyWords()
Locate the keywords in the article indicated by the tag
and add those keywords in alphabetical order to a keyword box.
makeKeyStyles()
Create an embedded style sheet for the keyword box.
replaceWS(textStr)
Replaces occurences of one or more consecutive white space
characters with the _ character.
*/
/* functions when the page is loaded */
window.addEventListener ("load", findKeyWords);
function findKeyWords() {
var findkeyWords = document.getElementByTagName("dnf");
var source = document.getElementById("doc");
var mainHeading = document.createElement("aside");
var mainHeading = document.createElement("h1");
mainHeading.setAttribute("id", "keyWords");
var headingText = document.createTextNode("KeywordList");
var keywordList = document.createElement("ol");
keywords.appendChild(mainHeadingText);
keyWordsElems = document.querySelectorAll("article#doc dfn");
var keyWords = document.getElementById("keyWords");
for (var i = 0; i < keyWordsElems.length; i++) {
}
}
/* Supplied Functions */
function replaceWS(textStr) {
var revText = textStr.replace(/\s+/g,"_");
return revText;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
