3

I have just started learning Javascript and Ok here is a code I want to try and see it in the browser, so I create a test.js file and put this in it:

function useless(callback) {
    return callback
}

var text = 'Amigo';

assert(
    useless(function(){ return text; }) === text,
    "The useless function works! " + text);

But still there is more, I should write a minimum HTML page than can call this function, What is sample HTML to host this method in it?

I have written something like this but still there is something wrong with it:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<script src="hehe.js" >
    useless('Amigo');
    window.onload=useless('Amigo')
</script>

</body>
</html>
4
  • 1
    So the book you're reading doesn't teach you how to incorporate js to a page and call functions? Commented Apr 3, 2013 at 20:20
  • @zerkms : No it doesn't have the HTML part...realign form Javascript Ninja book Commented Apr 3, 2013 at 20:21
  • "I have written something like this" --- where did you see that syntax? Just put something random and expected it to work? Commented Apr 3, 2013 at 20:21
  • 1
    Take a look at jsfiddle and jsbin Commented Apr 3, 2013 at 20:21

1 Answer 1

2
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script type="text/javascript" src="hehe.js"></script>
<script  >
    useless('Amigo');
    window.onload=useless('Amigo')
</script>

</body>
</html>

You can load the source in a separate script from the inline one that you call it in. Note that this assumes that hehe.js is in the root directory of your site.

For testing js in general jsFiddle is a nice resource that lets you define your html/js/css and experiment with small changes without having to write out all the files.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks but that still didn't show anything on the browser. Actually for the assert function I have used in the JS part, the IDE is saying "unresolved symbol"
Assert is not a built in JS function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.