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

200
Views
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 answers
Answer question

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 Report

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