xxxxxxxxxx
43
let url = 'https://restcountries.com/v3.1/all?fields=name,flags';
let chosenCountriesFlag;
let choices = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(75);
if (chosenCountriesFlag){
image(chosenCountriesFlag, 50, 50, 300, 200);
fill(255);
text(`1. ${choices[0].name.common} 2. ${choices[1].name.common} 3. ${choices[2].name.common}`,50, 300)
}
}
async function getFlag() {
choices = [];
let response = await fetch(url);
let countries = await response.json();
let randomCountry = floor(random(0, countries.length));
choices.push(countries[randomCountry]);
let randomCountry2 = floor(random(0, countries.length));
choices.push(countries[randomCountry2]);
let randomCountry3 = floor(random(0, countries.length));
choices.push(countries[randomCountry3]);
let neo = floor(random(3));
chosenCountriesFlag = loadImage(choices[neo].flags.png);
chosenName = choices[neo].name.common;
image(chosenCountriesFlag, 50, 50, 300, 200)
}
function mousePressed(){
getFlag();
}