I need to write a javascript program that will ask the user to enter a string of lower‐case characters and then print its corresponding two‐digit code. For example, if the input is “home”, the output should be 08151305. So far I can get it to return the correct numbers, but I cannot get it to add the zero in front of the number if it is a single digit This is what I have:
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name = prompt("Please enter a string of lowercase characters");
document.write(name,'<br>');
document.write('Length of the input is ', name.length,'<br>');
document.write("<br>")
for (i=0; i < name.length; i++)
{
{
document.write(i, ", ",name.charCodeAt(i) - 96, '<br>');
}
}
}
</script>
</head>
<body>
<input type="button" onClick="show_prompt()"value="CSE 201 HW#4 Problem 3"/>
</body>
</html>