Create links

Objectives

  • Create and use an array in JavaScript
  • Use a loop to process an array
  • Create HTML elements using JavaScript
  • Create and set HTML attributes using JavaScript
  • Upload files to a remote server
  • Create subdirectories and organize files on a remote server
  • Test and debug a website

Overview

This assignment involves creating a list of links on a web page after it has been loaded into a browser. The web page starts off with almost nothing on it. As soon as the page is done loading JavaScript should take over and add a list of properly functioning hypertext links to the page. The data for the links will be stored in an array in the JavaScript file.

Resources

Requirements

  • The starting HTML page has already been created for you. The only things you should change are the file extension (from .html.txt to .html) and the comments (to add your name and change the date). The only other changes you are allowed to make to the createLinks.html file are the names of the subdirectories that the CSS and JavaScript files are stored in.
  • The starting CSS file has already been created for you. The only things you should change are the file extension (from .css.txt to .css) and the comments (to add your name and change the date).
  • The JavaScript file has these requirements:
    • It should be named createLinks.js and be located in a subdirectory named scripts or javascript or js.
    • Create documentation comments at the start of the file which include the name of the file, your name, the course number, the date, and a short description of what the code does. See the .css and .html starting files for examples of documentation comments. JavaScript block comments look like CSS block comments.
    • Create an array which holds the URLs of at least four websites that you like. The URLs are strings that start with http://.
    • Create a function that does the following:
      • Get a reference to the element with the id links and store that reference in a variable.
      • Create a new ordered list (ol) element and store it in a variable.
      • Add (append) the ordered list as a child of the parent element of the "links" element.
      • Create a loop that will process each member of your array of URLs. The loop must do the following:
        • Create a list item (li) element and store the reference in a variable.
        • Create an anchor (a) element and store the reference in a variable.
        • Create a text node containing the text from the appropriate element of your URLs array and store that reference in a variable.
        • Set the "href" attribute of the anchor element to be the value of the appropriate element of your URLs array.
        • Add the text node to the anchor element as a child node.
        • Add the anchor element to the list item element as a child node.
        • Add the list item element to the ordered list element as a child node.
    • Write a statement that will run the above function as soon as the page is done loading (when window.onload is triggered).
  • Upload your files (including subdirectories) to the remote server. Test and debug your program. When you are done, let the instructor know via D2L dropbox that your assignment is ready to be graded.

Grading rubric

  • 2 pts: HTML file uploaded properly, comments modified properly, and no unallowed changes made.
  • 2 pts: CSS file uploaded properly to subdirectory, comments modified properly, and no unallowed changes made.
  • 2 pts: JavaScript file uploaded properly to subdirectory and named correctly.
  • 2 pts: JavaScript file has required documentation comments.
  • 3 pts: Array is properly created.
  • 2 pts: Function created properly.
  • 2 pts: The main element (id = links) obtained.
  • 2 pts: The ordered list is created.
  • 2 pts: The ordered list is added to the document.
  • 5 pts: The loop for processing the array is correct.
  • 2 pts: The list items are created properly.
  • 2 pts: The anchors are created properly.
  • 2 pts: The text nodes are created properly.
  • 2 pts: The text nodes are added to the anchors correctly.
  • 2 pts: The anchors work properly (the href attribute is set correctly).
  • 2 pts: The anchors are added to the list items.
  • 2 pts: The list items are added to the list.
  • 2 pts: The window.onload function is properly used to call your function after the page has loaded.

Example

Working createLinks assignment example
Working createLinks assignment screenshot

createLinks.html

createLinks.css