THE COUNTER CREATED USING JAVASCRIPT NOT WORKING [closed] - javascript

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>

Related

Only first button works. Not sure if its the script. It might be I'm missing a rule [closed]

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
I know I'm a beginner at this, but I really need to learn the rules. I'm trying to make a simple example of javascript. Its a box with three buttons, but for some reason only one of them works. They do have different ID types, so there must be another rule I don't know.
<!DOCTYPE html>
<html>
<head>
<title>Javascript box</title>
</head>
<body>
<p>Press buttons to change the box</p>
<div id="box" style="height:100px; width:100px; background-color: limegreen; margin:50px"></div>
<br>
<button id="less">less</button>
<button id="more">more</button>
<button id="none">Reset</button>
<script type="text/javascript">
document.getElementById("less").addEventListener("click", function(){
document.getElementById("box").style.height = "25px";
});
document.getElementByID("more").addEventListener("click", function(){
document.getElementById("box").style.height = "150px";
});
document.getElementById("none").addEventListener("click", function(){
document.getElementById("box").style.height = "100px";
});
</script>
</body>
</html>
For the second addEventListener, there's a typo.
In document.getElementByID, the D should not be capitalised.
A good way to debug these issues is to look at the console in developer tools.

HTML/JS site does not update html when using javascript [closed]

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

toastr is not defined [closed]

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".

How do I get the value of math.random and test it in an if statement? [closed]

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.

'document.writeln(something(params))' does nothing [closed]

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));

Categories