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

126
Views
Usar el interruptor para mostrar la respuesta a un número de la API

He creado una página web que devuelve la edad de una persona en función de su nombre.

Decidí usar una declaración de cambio para mostrar un mensaje basado en la edad devuelta por la API, pero no se mostrará en la página web. ¡Cualquier ayuda es apreciada!

 const btn = document.querySelector(".btn"); //Button to initiate API request const getAge = async (name) => { const response = await fetch(`https://api.agify.io?name=${name}`); //API url used to request age after name is submitted const data = await response.json(); console.log(data); const header = document.querySelector('.header'); //Response from API is displayed after message const message =`Your Age is:`; header.textContent = message; const content = document.querySelector('.content'); //Actual age returned from API content.textContent = data.age; }; btn.addEventListener("click", (e) => { //Event listening for button click e.preventDefault; const name = document.querySelector(".input-item").value; getAge(name); }); var a = content; switch(data.age(a)) { case a<=18: document.write("Just a youngin!") //if e<=18 break; case a>=19 && a<40: document.write("Mid-life crisis incoming!") //if e>=19 && e<=40 break; case a>=41: document.write("Too Old!") //if e>=41 break; }
about 4 years ago · Juan Pablo Isaza
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!