3

Here is the code that I am using.

JS

const clockContainer = document.querySelector('.js-clock'),
  clockTitle = clockContainer.querySelector('h1');

  function getTime() {
    const date = new Date();
    const minutes = date.getMinutes();
    const hours = date.getHours();
    const seconds = date.getSeconds();
    clockTitle.innerText = `${hours}:${minutes}:${seconds}`;
  }

function init() {
  getTime();
}

init();
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>clock</title>
</head>
<body>
    <div class="js-clock">
        <h1>00:00</h1>
    </div>
    <script src="clock.js"></script>
</body>
</html>

Its not working in CodeSandbox but able in vscode why?

I don't know why.... I have tried almost everything, but this code doesn't working in codesandbox

Jay
  • 2,648
  • 4
  • 29
  • 58
badbeoti
  • 33
  • 3

1 Answers1

2

You will notice that the code runs in the stack overflow integrated code running (notice the run code snippet box)

So, your code is fine. visual studio code is obviously fine. I think the issue is with code sandbox.

Here are my suggestions.

  • try a brand new sandbox, and run the code again.
  • try a new code sandbox website. my personal recommendation is codepen, as that is what I have experience using.
  • lastly, why not update your question with the link to your code sandbox? we could take a look and see for ourselves, why it is not working.

Also, it might be a good idea to raise a ticket or support request with code sandbox, and tell them that you are facing this issue. Or simply, link to this stack question so they can get all the details.

Jay
  • 2,648
  • 4
  • 29
  • 58
  • oh i got it! i re-coded in the sandbox where I had been coding. so i made a new box and it works well! im did this dumbshit-https://codesandbox.io/s/pcs-vy3ub?file=/index.html – badbeoti Apr 25 '20 at 07:59
  • there you go :) – Jay Apr 25 '20 at 08:00