I have downloaded distribution code from cs50. In that, what they written in inbox.js is executed only. What I have added to the inbox.js is not being executed. The code they have given:
document.addEventListener("DOMContentLoaded", function () {
// Use buttons to toggle between views
document
.querySelector("#inbox")
.addEventListener("click", () => load_mailbox("inbox"));
document
.querySelector("#sent")
.addEventListener("click", () => load_mailbox("sent"));
document
.querySelector("#archived")
.addEventListener("click", () => load_mailbox("archive"));
document.querySelector("#compose").addEventListener("click", compose_email);
// By default, load the inbox
load_mailbox("inbox");
});
function compose_email() {
// Show compose view and hide other views
document.querySelector("#emails-view").style.display = "none";
document.querySelector("#compose-view").style.display = "block";
// Clear out composition fields
document.querySelector("#compose-recipients").value = "";
document.querySelector("#compose-subject").value = "";
document.querySelector("#compose-body").value = "";
}
function load_mailbox(mailbox) {
// Show the mailbox and hide other views
document.querySelector("#emails-view").style.display = "block";
document.querySelector("#compose-view").style.display = "none";
// Show the mailbox name
document.querySelector("#emails-view").innerHTML = `<h3>${
mailbox.charAt(0).toUpperCase() + mailbox.slice(1)
}</h3>`;
In load_mailbox function, I have added:
fetch(`/emails/${mailbox}`)
.then((response) => response.json())
.then((emails) => {
console.log(emails);
});
But when I clicked buttons to see if my console working or not. I do not see any results from my console. If I copy the code I added(fetch(...)) and paste it on the console, it works. How do I implement that when I click buttons the results printed in the console? I have searched source tab to see if my code is added or not. But source tab only shows the code what they(cs50) have provided, not mine. What changes should I have to make to my code so that source tab also loads my code? I have seen related questions and answers on this topic, but they do not work here.