xxxxxxxxxx
39
/*
This challenge is designed for you to practice creating and loading, and reading json obect.
If you need an example use this one, https://editor.p5js.org/ptiarram/sketches/_itLxuyJ5
*/
//STEP 1 CREATE A VARIABLE FOR THE JSON OBJECT
let fact;
//use the preload function to load the json into the variable
function preload(){
//STEP 2 WRITE ONE LINE OF CODE TO LOAD THE JSON BELOW
// https://asli-fun-fact-api.herokuapp.com/
fact = loadJSON("https://asli-fun-fact-api.herokuapp.com/")
}
//the setup function runs one time
function setup() {
createCanvas(400, 400) // create the canvas space
noLoop();
}
//this draw function will only draw once because I have noLoop() in the setup function
function draw() {
background('white') //canvas background color
fill('gold')
rect(0,100,width,200) //fact area
textSize(20);
textWrap(WORD);
textFont('Georgia');
fill('black')
//STEP 3 REPLACE THE WORD VARIABLEHERE WITH FACT LOCATION
text(fact.data.fact,20,125,width-20,200)
//BONUS ADD ANOTHER TEXT THAT CONTAINS THE CAT - CATEGORY
text(fact.data.cat,20,225,width-20,200)
}