Working with JSON files - I have to recall a certain value with mousePressed() in a specific category.
In my code you have the following code :
var chuckData;
function setup () {
createCanvas (displayWidth, 500);
loadJSON("https://api.icndb.com/jokes/random", getData);
}
function draw () {
background(220);
if (chuckData) {
text(chuckData.value.joke, 10, 200);
}
}
function getData(data) {
chuckData = data;
}
function mousePressed () {
text(chuckData.value.joke, 100, 200);
}
In this code I load the link --> https://api.icndb.com/jokes/random (clicking the link will highlikely show 1 joke. but changes on refresh)
There is a section called “joke” I need to retrieve a joke from, and then generate it into text on screen.
This being :
if (chuckData) {
text(chuckData.value.joke, 10, 200);
}
}
I managed to get the text to print on the screen, and it changes the joke on refresh, however: I need to get this effect when using mousePressed() and fail to find out how to do it or find it on the internet.
Any help is appreciated!