« first day (4068 days earlier)      last day (1102 days later) » 

16:32
@MisterGeeky Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
1 message moved to Trash can
So, I'm doing: app.get('/', (req, res) => { res.sendFile('./index.html', { root: __dirname }) }) and in my html file, there's a <img src="./img.jpg"> that's not loading. Can you tell me why?
17:18
@MisterGeeky Because you don't have "img.jpg"? Or it is not exposed in the root web directory? Or perhaps it's ghosts? I'm not sure which answer would satisfy you. At the moment all three are equally likely. I suggest you start with looking at the network tab for what happens when the browser tries to GET the img.jpg. And if you see 599 Server is Haunted you know who you gonna call. If it's something different, you'd have an idea what to check.
@VLAZ Yeah, I got a 404 Cannot GET /img.jpg ... I probably need to set up a public folder.
Yup, adding app.use(express.static('.')) fixed it.
Dev tools to the rescue
user17382064
18:04
vlaz
user17382064
I am currently working on converting this forEach to a simple for Loop.

This one is a little bit more complicated to figure out.
user17382064
 function findPlayers() {
    const allCovers = document.querySelectorAll(".cover");
    const allWrappers = document.querySelectorAll(".wrap");
    allWrappers.forEach(function addToPlayers(cover, index) {
      players.push({
       "cover": cover,
       "wrapper": allWrappers[index]
      });
    });
  }
allWrappers.forEach(function addToPlayers(cover, index) -> for (const [index, cover] of allWrappers)
And remove the extra ); at the end.
user17382064
  function findPlayers() {
    const allCovers = document.querySelectorAll(".cover");
    const allWrappers = document.querySelectorAll(".wrap");
    for (const [index, cover] of allWrappers) {
      players.push({
        "cover": cover,
        "wrapper": allWrappers[index]
      });
    }
  }
Yep
user17382064
18:11
Wait, I had a mistake allWrappers should have been allWrappers.entries()
user17382064
  function findPlayers() {
    const allCovers = document.querySelectorAll(".cover");
    const allWrappers = document.querySelectorAll(".wrap");
    for (const [index, cover] of allWrappers.entries()) {
      players.push({
        "cover": cover,
        "wrapper": allWrappers[index]
      });
    }
  }
Yes, this should now be correct
user17382064
Would it have been able to be written using this setup?
user17382064
for (let i = 0; i < allWrappers.length; i++) {
18:16
Yes, you can also do that. In that case cover would be allCovers[i] and allWrappers[index] should be allWrappers[i]
user17382064
Like this:
user17382064
  function findPlayers() {
    const allCovers = document.querySelectorAll(".cover");
    const allWrappers = document.querySelectorAll(".wrap");
    for (let i = 0; i < allWrappers.length; i++) {
      players.push({
        "cover": allCovers[i],
        "wrapper": allWrappers[i]
      });
    }
  }
user17382064
user17382064
18:31
@VLAZ Question, All forEach codes, or standard for Loop codes can be written using for of instead?
arr.forEach() is identical to a straight for (let i = 0; i < arr.length; i++) however, with a .forEach() you cannot "skip" with continue;, you cannot manipulate the iteration by changing the index (e.g., i-- to go back one element or i += 2 to skip the next two), you cannot break; out of it, nor would return; stop it. A .forEach() always goes over all elements in the array in sequence.
So, if a for loop does none of these things - so, it goes over all elements of the array in sequence (which is mostly the case), then it's pretty much identical to .forEach()
user17382064
How would this be written using for of?
user17382064
  function hideAll(elements) {
    elements.forEach(hide);
  }
user17382064
This is using standard for loop.
user17382064
  function hideAll(elements) {
    for (let i = 0; i < elements.length; i++) {
      hide(elements[i]);
    }
  }
user17382064
18:43
for of would be written how?
for (const element of elements) {
  hide(element);
}
user17382064
elements is not defined"
It's the parameter of the function?
user17382064
const manageCover = (function makeManageCover() {
  const config = {};
  const body = document.body;
  let currentPlayButton = {};

  function show(el) {
    el.classList.remove("hide");
  }

  function hide(el) {
    el.classList.add("hide");
  }

  for (const element of elements) {
    hide(element);
  }
18:48
Uh, you don't have elements in that code. The one you showed me did have it
user17382064
The code runs using:
user17382064
  function hideAll(elements) {
    for (let i = 0; i < elements.length; i++) {
      hide(elements[i]);
    }
  }
hi nerds
user17382064
 function hideAll(elements) {
    elements.forEach(hide);
  }


converts to:


  function hideAll(elements) {
    for (let i = 0; i < elements.length; i++) {
      hide(elements[i]);
    }
  }
user17382064
@VLAZ Would this be changed to something else?
user17382064
18:51
for (const element of elements) {
  hide(element);
}
i came here to ask for help, then i saw this:

>Do not spam. This is a fairly simple rule, do not repost questions because you did not get an answer right away. It was likely we read it and just didn't care. Tough luck. There are times when the room gets carried away with images or oneboxes, but this is no excuse to make a habit of it.
function hideAll(elements) {
  for (const element of elements) {
    hide(element);
  }
}
user17382064
@VLAZ I attempted to do this one but did it wrong.
user17382064
 /* function addClickToExit(exitButtons) {
    exitButtons.forEach(function addExitButtonHandler(exitButtons) {
      exitButtons.addEventListener("click", exitClickHandler);
    });
  }*/

  function addClickToExit(exitButtons) {
for (const [exitButtons] of exitButtons){
      exitButtons.addEventListener("click", exitClickHandler);
    });
  }
for (const [exitButtons] of exitButtons){ -> for (const exitButton of exitButtons){
19:02
does anyone know about this? stackoverflow.com/questions/70237426/…
user17382064
@VLAZ This:
user17382064
 function addClickToExit(exitButtons) {
    exitButtons.forEach(function addExitButtonHandler(exitButtons) {
      exitButtons.addEventListener("click", exitClickHandler);
    });
  }
user17382064
Becomes this?
user17382064
  function addClickToExit(exitButtons) {
     for (const exitButton of exitButtons){
      exitButtons.addEventListener("click", exitClickHandler);
    }
  }
user17382064
exitButtons.addEventListener is not a function
user17382064
19:13
Would this need to be added to the for of code? function addExitButtonHandler
user17382064
20:05
How would that be fixed?
user17382064
20:17
Practicing a few of these will help me to be able to do them on my own.
user17382064
20:31
I fixed it:
user17382064
  function addClickToExit(exitButtons) {
     for (const exitButton of exitButtons){
      exitButton.addEventListener("click", exitClickHandler);
    }
  }
user17382064
Next:
user17382064
 function addExitHandlers(callback) {
    const resetVideo = document.querySelectorAll(".exit");
    resetVideo.forEach(function resetVideoHandler(video) {
      video.addEventListener("click", callback);
    });
  }
user17382064
My attempt: .for is not iterable
user17382064
  function addExitHandlers(callback) {
    const resetVideo = document.querySelectorAll(".exit");
      for (const [video] of resetVideo) {
      video.addEventListener("click", callback);
    }
  }
user17382064
21:02
Fixed:
user17382064
  function addExitHandlers(callback) {
    const resetVideo = document.querySelectorAll(".exit");
      for (const video of resetVideo) {
      video.addEventListener("click", callback);
    }
  }
user17382064
Next:
user17382064
  function addClickToButtons(playButtons) {
    playButtons.forEach(function playButtonHandler(playButton) {
      playButton.addEventListener("click", coverClickHandler);
    });
  }
user17382064
Attempt: Cannot read properties of undefined (reading 'classList')
user17382064
  function addClickToButtons(playButtons) {
   for (const playButton of playButtons){
      playButton.addEventListener("click", coverClickHandler);
    }
  }
user17382064
21:11
I thought I did that one right.
user17382064
I was looking at code that I was working on, and not an already working piece of code.

This works:
user17382064
  function addClickToButtons(playButtons) {
    for (const playButton of playButtons) {
      playButton.addEventListener("click", coverClickHandler);
    }
  }
22:48
why does typescript use the language of "compiling"?
nothing is compiled. At best typescript transpiles.
143
Q: Compiling vs Transpiling

Nishi MahtoWhile searching about the difference, I came across these definitions: Compiling is the general term for taking source code written in one language and transforming into another. Transpiling is a specific term for taking source code written in one language and transforming into another language...

Transpilers are a subset of compilers. And a compiler can take input in one language and output it into another. You can compile C to assembly for example.
user17382064
23:05
Converting this from forEach to for of, how would it be written?
user17382064
  function resetBackground(backgroundSelector) {
    const allBackgrounds = document.querySelectorAll(backgroundSelector);

    function hideBackground(background) {
      background.classList.add("bg1");
    }
    allBackgrounds.forEach(hideBackground);
  }
user17382064
23:28
That one has me confused.
user17382064
Because it is not written similar to the other ones.
user17382064
This is wrong.
user17382064
  function resetBackground(backgroundSelector) {
    const allBackgrounds = document.querySelectorAll(backgroundSelector);

    function hideBackground(background) {
      background.classList.add("bg1");
    }

    for (const allBackground of allBackgrounds) {
      hideBackground(allBackgrounds);
    }
  }
user17382064
23:49
I'm stuck on that one.

« first day (4068 days earlier)      last day (1102 days later) »