Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

515
Visualizações
ReferenceError: color is not defined

I am learning the concepts of Functional Programming and came across an exercise that has me pretty stumped. When I go to Invoke consoleStyler() in Task 4, it gives me a Reference Error: color is not defined. I followed the step by step instructions on the course to get this current code as well as played around with it myself and I can't seem to satisfy the error. Could someone explain to me why I am getting this error? I genuinely would like to understand what I am doing wrong.

// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
    var message = "%c" + txt;
    var style = `color: ${color};`
    style += `background: ${background};`
    style += `font-size: ${fontSize};`
    console.log(message, style);
}

// Task 2: Build another console log message generator
function celebrateStyler(reason) {
    var fontStyle = "color: tomato; font-size: 50px";
    if (reason == "birthday") {
        console.log(`%cHappy Birthday`, fontStyle);
    } else if (reason == "champions") {
        console.log(`%cCongrats on the title!`, fontStyle);
    } else {
        console.log(message, style);
    }
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler('#1d5c63', '#ede6db', '4px', 'Congrats!');
celebrateStyler('birthday');

// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate() {
    consoleStyler(color, background, fontSize, txt);
    celebrateStyler(reason);
}
// Call styleAndCelebrate
styleAndCelebrate('ef7c8e', 'fae8e0', '30px', 'You made it!', 'Champions')
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I've moved the consoleStyler and celebrateStyler functions with your input params inside the styleAndCelebrate(). The reason it wasn't working before was because due to scoping, styleAndCelebrate() didn't know that value of the params inside its function. Hope this helps.

// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
  var message = "%c" + txt;
  var style = `color: ${color};`
  style += `background: ${background};`
  style += `font-size: ${fontSize};`
  console.log(message, style);
}

// Task 2: Build another console log message generator
function celebrateStyler(reason, txt) {
  var message = "%c" + txt;
  var fontStyle = "color: tomato; font-size: 50px";
  if (reason == "birthday") {
    console.log(`%cHappy Birthday`, fontStyle);
  } else if (reason == "champions") {
    console.log(`%cCongrats on the title!`, fontStyle);
  } else {
    console.log(message, fontStyle);
  }
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions


// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate() {
  consoleStyler('#1d5c63', '#ede6db', '4px', 'Congrats!');
  celebrateStyler('champions');
}
// Call styleAndCelebrate
styleAndCelebrate();

about 4 years ago · Juan Pablo Isaza Relatório

0

Your problem is your code is trying to use variables that haven't been declared.

The first error is in Task 2, the last else tries to log using the non-existent variables 'message' and 'style'. I assume that was from the exercise and you just forgot to update those like you did with the other conditions.

The other error is in Task 4. When you execute Task 4 you pass it 5 values, but your function declaration for Task 4 doesn't contain any of those input variables.

Task 4 should read as the below to work:

// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
    consoleStyler(color, background, fontSize, txt);
    celebrateStyler(reason);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda