let fruits = [`apple`, `orange`, `banana`] for (let fruit of fruits) { console.log(fruit) }
let word = `dog` for (let character of word) { console.log(character) }
HTML
<button id="numbersButton">Show numbers</button> <p id="numbersParagraph">Numbers:</p>
JavaScript
let numbersButton = document.getElementById(`numbersButton`) let numbersParagraph = document.getElementById(`numbersParagraph`) let numbers = [1, 1, 2, 3, 5] numbersButton.addEventListener(`click`, showNumbers) function showNumbers() { for (// your code will appear here) { numbersParagraph.innerHTML = `${numbersParagraph.innerHTML} ${number}` } }
Your code
Test your code
Numbers:
HTML
<button id="wordsButton">Show words</button> <p id="wordsParagraph">Words:</p>
JavaScript
let wordsButton = document.getElementById(`wordsButton`) let wordsParagraph = document.getElementById(`wordsParagraph`) let words = [`one`, `two`, `three`, `four`, `five`] wordsButton.addEventListener(`click`, showWords) function showWords() { for (// your code will appear here) { wordsParagraph.innerHTML = `${wordsParagraph.innerHTML} ${word}` } }
Your code
Test your code
Words:
HTML
<button id="sumButton">Show sum</button> <p id="sumParagraph">Sum:</p>
JavaScript
let sumButton = document.getElementById(`sumButton`) let sumParagraph = document.getElementById(`sumParagraph`) let numbers = [1, 2, 3, 4, 5] sumButton.addEventListener(`click`, showSum) function showSum() { let runningTotal = 0 for (let number of numbers) { // your code will appear here } sumParagraph.innerHTML = `Sum: ${runningTotal}` }
Your code
Test your code
Sum:
HTML
<button id="positiveButton">Show how many positive</button> <p id="positiveParagraph">How many positive:</p>
JavaScript
let positiveButton = document.getElementById(`positiveButton`) let positiveParagraph = document.getElementById(`positiveParagraph`) let numbers = [5, -2, 0, 3, -7] positiveButton.addEventListener(`click`, showPositive) function showPositive() { let numPositive = 0 for (let number of numbers) { if (// your code will appear here) { numPositive = numPositive + 1 } } positiveParagraph.innerHTML = `How many positive: ${numPositive}` }
Your code
Test your code
How many positive:
HTML
<button id="lettersButton">Show letters</button> <p id="lettersParagraph">Letters:</p>
JavaScript
let lettersButton = document.getElementById(`lettersButton`) let lettersParagraph = document.getElementById(`lettersParagraph`) let word = `hello` lettersButton.addEventListener(`click`, showLetters) function showLetters() { for (// your code will appear here) { lettersParagraph.innerHTML = `${lettersParagraph.innerHTML} ${letter}` } }
Your code
Test your code
Letters:
HTML
<button id="spacesButton">Show how many spaces</button> <p id="spacesParagraph">How many spaces:</p>
JavaScript
let spacesButton = document.getElementById(`spacesButton`) let spacesParagraph = document.getElementById(`spacesParagraph`) let string = `How are you today?` spacesButton.addEventListener(`click`, showSpaces) function showSpaces() { let numSpaces = 0 for (let character of string) { if (// your code will appear here) { numSpaces = numSpaces + 1 } } spacesParagraph.innerHTML = `How many spaces: ${numSpaces}` }
Your code
Test your code
How many spaces: