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

130
Views
Imprima un mensaje para una condición específica, un mensaje diferente para todo lo demás

Mi página de inicio le solicita que ingrese su nombre al ingresar, pero quiero que imprima un mensaje especial cuando ingrese mi apodo. En su lugar, imprime el mismo mensaje cada vez.

 window.onload = function namePrompt() { let person = prompt("Please enter your name", ""); if (person != null) { document.getElementById("name").innerHTML = "welcome, " + person + ", to the pyrogaming/covid2009 homepage!"; } else if (person = pyro || Pyro || PYRO) { document.getElementById("name").innerHTML = "hey, me! hope you've been making substantial changes!"; } }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

person = pyro || Pyro || PYRO no es JS válido

Hay tres errores. = es asignación, no comparación y necesitaría cotizaciones y probar cada una con ===

 person === "pyro" || person ==="Pyro" || person === "PYRO"

En su lugar, use toLowerCase y un ternario . En cualquier caso, mantente SECO (No te repitas)

También recomiendo eventListener en lugar de onload

 window.addEventListener("DOMContentLoaded", () => { const person = prompt("Please enter your name", ""); if (!person) return; // empty string or null const text = person.toLowerCase() === "pyro" ? "hey, me! hope you've been making substantial changes!" : `welcome, ${person}, to the pyrogaming/covid2009 homepage!`; document.getElementById("name").innerHTML = text; })
 <span id="name"></span>

about 4 years ago · Juan Pablo Isaza Report

0

  1. Primero debe verificar el nombre si es suyo y luego mostrar el mensaje predeterminado
  2. Al comparar, use === , no = - este es "asignar valor", no comparar
  3. Use valores de cadena en lugar de solo PYRO
  4. También sugeriría usar el método toLowerCase , para que no tenga que preocuparse por el caso de entrada. "Pyro", "PYRO", "pyro": todos serán iguales para comparar

 window.onload = function namePrompt() { let person = prompt("Please enter your name", ""); if (person != null) { if(person.toLowerCase() === 'pyro') { document.getElementById("name").innerHTML = "hey, me! hope you've been making substantial changes!"; } else { document.getElementById("name").innerHTML = "welcome, " + person + ", to the pyrogaming/covid2009 homepage!"; } } }
 <div id="name"></div>

about 4 years ago · Juan Pablo Isaza Report

0

 window.onload = function namePrompt() { let person = prompt("Please enter your name", ""); var msg if (person != null) { if (person.toLowerCase() == "pyro") { msg = "hey, me! hope you've been making substantial changes!"; } else { msg = "welcome, " + person + ", to the pyrogaming/covid2009 homepage!"; } document.getElementById("name").innerHTML = msg } }
 <div id="name"></div>

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!