Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am newbie of JavaScript and studying with textbook. I wrote below code, and alert modal window was displayed correctly, but document.writeln(triangle(8,5)) does nothing. Why?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Area of Triangle</title>
</head>
<body>
<h1>Area of Triangle</h1>
<pre>
<script type="text/javascript" charset="utf-8">
<!--
var triangle;
triangle = function(base, height) {
return base * height / 2;
};
alert(triangle(8, 5));
documnt.writeln(triangle(8, 5));
-->
</script>
</pre>
</body>
</html>
Thank you for your kindness.
You've misspelled document as documnt. Try:
document.writeln(triangle(8, 5));
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
<!DOCTYPE html>
<html>
<head>
<script>
let counter= 0;
function count() {
counter++;
document.querySelector('#counter').innerHTML= counter;
}
</script>
<title>My Webpage</title>
</head>
<body>
<h1 id="counter">0</h1>
<button onlclick="count()">Click Here!</button>
</body>
</html>
when i am running it on internet explorer and also on an online IDE for html the page displays 0 and click here but when i click on the button the page remains the same and the 0 not changes to 1.
Please help what changes can i make
You have a typo in onclick, here is the working version.
let counter = 0;
function count() {
counter++;
document.querySelector('#counter').innerHTML = counter;
}
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1 id="counter">0</h1>
<button onclick="count()">Click Here!</button>
</body>
</html>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I really don't know what I am doing wrong but my site just won't update the .innerHtml of the heading. There is no error in the browser console and console.log() returns the right string ("hhh").
Both elements with id = test and teet won't update their html
<html>
<head>
<title>
test title
</title>
</head>
<body>
<h1 id="teet">TEST HEADING</h1>
Search :
<input id="input">
<button onclick="load()" id="submit" type="button"> search </button>
<br>
<h1 id="test"> Test</h1>
<script>
function load() {
var test = document.getElementById("test").innerHtml = "hhh";
console.log(test);
}
</script>
</body>
</html>
It's innerHTML with capital letters
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Receiving the following error in developer console when loading the page:
Uncaught ReferenceError: toastr is not defined
Here are the html contents. Can someone please explain to me why toastr is undefined?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">
</head>
<body>
<p>Toastr TEST</p>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<script scr="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.2/js/toastr.min.js">
</script>
<script>
$(document).ready(function() {
console.log("document.ready");
toastr.info('document.ready');
});
$(window).load(function() {
console.log("window.load");
toastr.info('window.load');
});
</script>
</body>
</html>
You have the script elemen's src attribute wrongly spelled for the toaster.js file, it should be "src" but is "scr".
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My html is like this:
<!DOCTYPE html>
<html>
<head>
<title>
Event Handling
</title>
</head>
<body>
<h1> This is the chapter in which I am handling Events.The site you should visit is: </h1>
<b>here<b>
<script src="events.js"></src>
</body>
</html>
The javascript is like this:
var link = document.getElementsByTagName("a")[0];
link.onclick = MyEventHandler;
function MyEventHandler()
{
alert("ouch!");
return false;
}
It is not working, but using inling event handler I am doing it successfully. Please helop me.
You need to assign the event handler function, not the return value of calling that function.
link.onclick = MyEventHandler;
(Also note that you need to use the end tag </script> not </src>.)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
EDIT Here is new code but it is still not working for me.
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="mycss.css">
<script src="myjavascript2.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<button onclick="myFunction()">Play</button>
<p id="test"></p>
</body>
</html>
Javascript:
var things = ['rock','paper','scissors'];
function myFunction() {
var i = Math.floor(Math.random()*things.length));
document.getElementById("test"+(i+1)).innerHTML=things[i];
}
I added this text so that it would let me post the edit, please ignore this.
You could simply replace your whole code with
var things = ['rock','paper','scissors'];
var i = Math.floor((Math.random()*things.length));
document.getElementById("test").innerHTML=things[i];
This would also let you more easily deal with other operations, like finding a winner.