How do I get JSON data via asynchronous communication in a class format?
I would like to be able to display the image after pressing the button button on HTML, but I looked into various class methods, but I didn't understand.If you understand, please help me.
There are many things I don't understand just a few months after I started studying as an engineer, so please be gentle with me.
const btn= document.getElementById("btn");
const dogImg = document.getElementById("dogImg");
// Click the button to activate the event
btn.addEventListener("click",()=>{
fetch("https://example.com/api")// API URL
.then(response)=>{
return response.json();
})
.then((myJson)=>{
// Put the URL image you got in the img tag
dogImg.src=myJson ["message"];
});
});
For example, a request such as "Replace integer multiplication with addition" or "Replace trinomial operator with if
" can be written with that much information.However, the code in the questionnaire doesn't know what should be classified, and I can't think of any particular advantage in using the class, so the answer is "no need to rewrite the code using the class."
There was a candidate who wondered if the class could be involved in the following situations.
© 2024 OneMinuteCode. All rights reserved.