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>"))
}
/*}*/
Your if condition is wrong.
if (i === 'a' || i === 'A') { is what you need, otherwise the statement reads:
if
iis equal to 'a' OR 'A' Instead of ifiis equal to 'a' ORiis equal to 'A'
Because you aren't comparing the second part to anything it will return true.
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>