I’m trying to make a simple counter, but its proving difficult, $ was undefined, but I used:
function jQuery($) {
'use strict';
$(function() {
//code here
});
};
While that fixed the $ problem, i can’t figure out how to make the counter. This is my code:
var counter = 0;
function appendNumber() {
const newElement = document.createElement('div');
newElement.textContent = counter;
document.body.appendChild(newElement);
counter++;
}
It says it’s reserved i need some other way to do const
, as it says “The keyword const
is reserved.”
If you find a solution to this, or a different way to do a counter, it would be much appreciated.
I tried just using a var
, then using append, but it just appended x
. (the var’s name)
This was some of the code I tried:
function jQuery($) {
'use strict';
function findAnswer() {
x = parseInt(x);
}
$(function() {
var $counter = $( ".counter" );
if (x < 0) {
answer = x * y;
}
$( ".counter" ).append("answer");
$( ".clickme" ).on("click", function() {
answer++;
$( ".counter" ).append ("answer")
});
});
}
The parseInt
was an idea I had, because is school, it had me make a calculator, using parseInt
.