scrimba
Frontend Career Path
React basics
Meme generator
Project: Add images to the meme generator
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Project: Add images to the meme generator
AboutCommentsNotes
Project: Add images to the meme generator
Expand for more info
components
Meme.js
run
preview
console
import React from "react"
import memesData from "../memesData.js"

export default function Meme() {
/**
* Challenge: Save the random meme URL in state
* - Create new state called `memeImage` with an
* empty string as default
* - When the getMemeImage function is called, update
* the `memeImage` state to be the random chosen
* image URL
* - Below the div.form, add an <img /> and set the
* src to the new `memeImage` state you created
*/

function getMemeImage() {
const memesArray = memesData.data.memes
const randomNumber = Math.floor(Math.random() * memesArray.length)
// memesArray[randomNumber].url <-- this line is incomplete!

}

return (
<main>
<div className="form">
<input
type="text"
placeholder="Top text"
className="form--input"
/>
<input
type="text"
placeholder="Bottom text"
className="form--input"
/>
<button
className="form--button"
onClick={getMemeImage}
>
Get a new meme image 🖼
</button>
</div>

</main>
)
}
Console
"https://i.imgflip.com/1ihzfe.jpg"
,
/index.html
-2:56