Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
error: var is not defined while it is defined
  1. I want to know, why it says that the third "S is not defined", because S is defind
function startTime() {
  const today = new Date();
  var S = today.getHours();
  var m = today.getMinutes();
  m = checkTime(m);
  document.getElementById('txt').innerHTML = S + ":" + m;
  setTimeout(startTime, 1000);
}

function checkTime(i) {
  if (i < 10) { i = "0" + i };  // add zero in front of numbers < 10
  return i;
}

this S here

var a = S + m
    
if (a === 2215) {console.log("lol"); };
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

var S,m;
function startTime() {
  const today = new Date();
  S = today.getHours();
  m = today.getMinutes();
  m = checkTime(m);
  document.getElementById('txt').innerHTML = S + ":" + m;
  setTimeout(startTime, 1000);
}

function checkTime(i) {
  if (i < 10) { i = "0" + i };  // add zero in front of numbers < 10
  return i;
}

var a = S + m
    
if (a === 2215) {console.log("lol"); };

You forgot to shift "S" to global scope, var has a function scope, if variable is declared with var, can access only it's function scope

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!