let fruits = [] fruits.push(`apple`) fruits.push(`orange`) fruits.push(`banana`)
fruits[0]
fruits.length
HTML
<input type="text" placeholder="word" value="hello" id="wordInput"> <button id="wordButton">Add word</button> <p id="wordsParagraph"></p>
JavaScript
let wordInput = document.getElementById(`wordInput`) let wordButton = document.getElementById(`wordButton`) let wordsParagraph = document.getElementById(`wordsParagraph`) let words = [] wordButton.addEventListener(`click`, addWord) function addWord() { // your code will appear here wordsParagraph.innerHTML = words }
Your code
Test your code
HTML
<button id="numberButton">Add number</button> <p id="numbersParagraph"></p>
JavaScript
let numberButton = document.getElementById(`numberButton`) let numbersParagraph = document.getElementById(`numbersParagraph`) let number = 0 let numbers = [] numberButton.addEventListener(`click`, addNumber) function addNumber() { number = number + 1 // your code will appear here numbersParagraph.innerHTML = numbers }
Your code
Test your code
HTML
<button id="randomNumberButton">Add random number</button> <p id="randomNumbersParagraph"></p>
JavaScript
let randomNumberButton = document.getElementById(`randomNumberButton`) let randomNumbersParagraph = document.getElementById(`randomNumbersParagraph`) let randomNumbers = [] randomNumberButton.addEventListener(`click`, addRandomNumber) function addRandomNumber() { let randomNumber = Math.floor(Math.random() * 10) // your code will appear here randomNumbersParagraph.innerHTML = randomNumbers }
Your code
Test your code
HTML
<button id="firstWordButton">Show first word</button> <p id="firstWordParagraph"></p>
JavaScript
let firstWordButton = document.getElementById(`firstWordButton`) let firstWordParagraph = document.getElementById(`firstWordParagraph`) let words = [`first`, `second`, `third`] firstWordButton.addEventListener(`click`, showFirstWord) function showFirstWord() { // your code will appear here }
Your code
Test your code
HTML
<button id="thirdWordButton">Show third word</button> <p id="thirdWordParagraph"></p>
JavaScript
let thirdWordButton = document.getElementById(`thirdWordButton`) let thirdWordParagraph = document.getElementById(`thirdWordParagraph`) let words = [`first`, `second`, `third`] thirdWordButton.addEventListener(`click`, showThirdWord) function showThirdWord() { // your code will appear here }
Your code
Test your code
HTML
<button id="randomWordButton">Show random word</button> <p id="randomWordParagraph"></p>
JavaScript
let randomWordButton = document.getElementById(`randomWordButton`) let randomWordParagraph = document.getElementById(`randomWordParagraph`) let words = [`first`, `second`, `third`] randomWordButton.addEventListener(`click`, showRandomWord) function showRandomWord() { let randomNumber = Math.floor(Math.random() * words.length) // your code will appear here }
Your code
Test your code