I made an app that assigns value to letters A-Z = 1-26 and sums them. How can i get the value of each letter from the input field? For example if i type 'bb' it will output b(2)+b(2) = 4 in span with id 'a'
https://codepen.io/anon/pen/pOvNXd
function myFunction() {
//code
var alp = {a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9, j:10, k:11, l:12, m:13, n:14, o:15, p:16, q:17, r:18, s:19, t:20, u:21, v:22, w:23, x:24, y:25, z:26, ' ':0, '"':0, "'":0, '!': 0, '#':0, '$':0, '%':0, '(':0, ')':0, '+':0, '-':0, '*':0, '/':0, '=':0, '_':0, '@':0, '?':0, '&':0, '.':0, ',':0, ':':0, ';':0}
//starting value
var str = document.getElementById("txt").value;
var n = str.length;
var total = 0;
//counter
for (var i = 0; i < str.length; i++)
total += alp[str[i]]
//output
document.getElementById("res").innerHTML = total;
document.getElementById("a").innerHTML = n;
}
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<center>
<h1>Task</h1><br>
<input type="text" name="fname" id="txt" style="width: 500px; font-size: 125%" size="60px" value="" placeholder="Type something..." oninput="myFunction()">
<br><br>
<p style="color: RGB(0,186,0)">Sum</p>
<span id="res" style="color: RGB(0,186,0)">0</span>
<br>
<p id="a">0</p>
</center>
</div>
</body>
</html>