I want to write an algorithm into javascript and I am sure I wrote true . the algorithm gives a number from user and gives the user the result : 1+3+5+...+(2n+1) and "n" is var. the javascript gives me errors : calc() is not defined , unexpected token;
<html>
<head>
<title>Algorithm</title>
<script type="text/javascript">
function calc(){
var n = document.getElementById('value').value;
var sum = 0, i = 1, k = 0;
for(k=0,k<n,k++){
sum = sum += i;
i+=2;
k++;
}
document.getElementById('answer').innerHTML = sum;
}
</script>
</head>
<body>
<input type="text" id="value" placeholder="Enter your number"/>
<button onclick="calc()">OK</button><br/>
<h1 id="answer"></h1>
</body>
sum = sum += i;looks dodgyforloop header, you should use;instead of,:for(k=0;k<n;k++){