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

516
Views
ReferenceError: el color no está definido

Estoy aprendiendo los conceptos de Programación Funcional y encontré un ejercicio que me tiene bastante perplejo. Cuando voy a Invocar consoleStyler() en la Tarea 4, aparece un Error de referencia: el color no está definido. Seguí las instrucciones paso a paso en el curso para obtener este código actual y jugué con él yo mismo y parece que no puedo satisfacer el error. ¿Alguien podría explicarme por qué me sale este error? Realmente me gustaría entender lo que estoy haciendo mal.

 // 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 answers
Answer question

0

He movido las funciones consoleStyler y celebrityStyler con sus parámetros de entrada dentro de celebrateStyler styleAndCelebrate() . La razón por la que no funcionaba antes era porque, debido al alcance, styleAndCelebrate() no conocía el valor de los parámetros dentro de su función. Espero que esto ayude.

 // 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 Report

0

Su problema es que su código está tratando de usar variables que no han sido declaradas.

El primer error está en la Tarea 2, el último intenta iniciar sesión usando las variables inexistentes 'mensaje' y 'estilo'. Supongo que eso fue del ejercicio y simplemente olvidaste actualizarlos como lo hiciste con las otras condiciones.

El otro error está en la Tarea 4. Cuando ejecuta la Tarea 4, le pasa 5 valores, pero su declaración de función para la Tarea 4 no contiene ninguna de esas variables de entrada.

La tarea 4 debería decir lo siguiente para que funcione:

 // 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 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!