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

201
Visualizações
I have this python code that I am trying to turn into javascript but I cant seem to figure out which if statement. to use

This is the python code im trying to convert into javascript.

ime = input("Enter your name: \n\n")

# correction made by AmyHubbertx
for c in ime:

    c = c.upper()
    if (c == "A"):
        print("..######..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")
    elif (c == "B"):
        print("..######..\n..#....#..\n..#####...\n..#....#..\n..######..\n\n")
    elif (c == "C"):
        print("..######..\n..#.......\n..#.......\n..#.......\n..######..\n\n")
    elif (c == "D"):
        print("..#####...\n..#....#..\n..#....#..\n..#....#..\n..#####...\n\n")

I want to be able to write anything and get each letter written to the page. This current code writes 'a' even if you put the wrong letter.

How can I input something and have it write to the page?

/*function yourName()*/
    let name = prompt("Enter Your Name")

    if (i === 'a' || 'A'){
        document.write(("..######..<br>..#........#..<br>..######..<br>..#........#..<br>..#........#..<br><br>"))
    } if ( i = 'b' || 'B'){
        document.write(("..######..<br>..#........#..<br>..#####...<br>..#........#..<br>..######..<br><br>"))
    } if ( i = 'c' || 'C'){
        document.write(("..######..<br>..#.......<br>..#.......<br>..#.......<br>..######..<br><br>"))
    }
/*}*/
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Your if condition is wrong.

if (i === 'a' || i === 'A') { is what you need, otherwise the statement reads:

if i is equal to 'a' OR 'A' Instead of if i is equal to 'a' OR i is equal to 'A'

Because you aren't comparing the second part to anything it will return true.

about 4 years ago · Santiago Trujillo Relatório

0

Many issues. = is assignment and == or === is comparison just like in Python.

Also not you should NEVER use document.write after the page has loaded. It will wipe the page.

Here is a working version taking all letters you type (as long as they are A, B, or C)

const name = prompt("Enter Your Name", "CAB").trim().toUpperCase()
let text = "No name given";

const chars = {
  'A': "..######..<br>..#....#..<br>..######..<br>..#....#..<br>..#....#..<br>",
  'B': "..######..<br>..#....#..<br>..#####...<br>..#....#..<br>..######..<br>",
  'C': "..######..<br>..#.......<br>..#.......<br>..#.......<br>..######..<br>",
}

if (name.length > 0) {
  text = name.split("").map(c => chars[c] || "X<br/>"); // return the character or X if not found
  document.getElementById("content").innerHTML = `<pre>${text.join("</pre><pre>")}</pre>`;
}
pre {display: inline-block; float: left }
<div id="content"></div>

about 4 years ago · Santiago Trujillo 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