This is a potential answer to the exercise: Test for an array item.
- Try validating the user input before testing:
inputValuevalue missing: "Please enter a Character Class";
This is a potential answer to the exercise: Test for an array item.
inputValue value missing: "Please enter a Character Class";When an array contains primitive values, you can use the Array.includes() method to test if a value exists within that array.
Array.includes() method, test if the entered command line value exists in the characterClasses array:
If true log the following to the console:
"[inputted value]" is a valid Character Class!`
The goal of this activity is to move the embedded Javascript and CSS in index.html to external files without breaking the page.
script element to an external file called script.js. Delete the now empty script element.index.html, link to this new Javascript file by adding a new script element in the head of the HTML file.
src attribute to relatively link to the new Javascript file you just created.defer to the script element. This ensures that the Javascript loads after the DOM has loaded (this is the same as putting the script at the bottom of the page).Some examples from this list of Public APIs.
These APIs return pretty simple data (usually a single object with a few properties).
In this activity, you will refactor the Picsum image gallery using an array of objects in animals.js:
alt attributes for each image;src of each image to a local jpg file;picsumIds array of numbers (in picsum-list.js with the picsumAnimals array of objects in animals.js.A possible solution to this forEach() Activity.
In this activity, you will generate a comma-separated list of nouns and display it on a web page.
For example, this array:
const nouns = [`one`, `two`, `three`];Should be display on the page as a sentence in the following format:
In this activity, you will take a list of image IDs listed in picsum-list.js and create a gallery of images using the Lorem Picsum service.
Lorem Picsum is an image service that allows you to embed placeholder photos into your web pages. The images are pulled from open-source Unsplash images.
For example, the following HTML displays this puppy image
<img src="https://picsum.photos/id/237/300/300" alt="Lorem Picsum Image">In this activity you will add a dynamic counter that displays the number of characters entered into a <textarea> element.
character-counter.js, create a textarea variable using document.querySelector().counter variable for the paragraph that will hold the current character count of textarea.Element.getAttribute() create a limit variable that holds the max character limit defined by the maxlength attribute of the textarea element.Element.addEventListener() and the input event, add an event handler to textarea that updates counter every time the user types a character.
textarea.value has all the same methods as any other string.