Well, good luck on learning, but you should probably check out a book on the subject like Javascript just the good parts. Also learning jQuery isn't a bad idea. I redid your example and changed it to accept user input and use a namespace. Its fine when starting out to just declare a function on the global namespace, but when you start getting into larger systems having overlapping methods is a problem.
And also learn how to use the chrome debugger, its essential in finding problems with javascript code. If you had the debugger open, you would have noticed the file name myjs,js didn't load a document, it would have probably logged a 404.
/* Lets declare a self executing method, it auto-executes and keeps the document clean */
(function(){
// Make a new namespace, i'm going to call it NS, but you could name it anything. This uses the OR logic to create if it doesn't exist.
window.NS = window.NS || {};
// Declare your function in the name space
NS.add = function(a, b) {
return a+b;
};
}());
/* Wait till the document is ready, magic jQuery method */
$(function(){
// No error prevention, this is just an example
// Wait till the user clicks Calculate
$('#Calculate').click(function(){
var A = $('#A').val() - 0; // Get #A value, convert to number by subtwacting 0
var B = $('#B').val() - 0; // Get #B value, convert to number
// Call your method and set the value of #C
$('#C').val(NS.add(A, B));
});
});
<!-- Use jQuery, its the best -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
<!-- Declare a few fields, we like user input -->
<input type="text" id="A" value="1000"/>
<input type="text" id="B" value="337"/>
<!-- Use this field to hold input -->
<input type="text" readonly id="C"/>
</div>
<!-- One button to rule them all -->
<button id="Calculate">Calculate</button>
myjs,jsthere's a comma here.