https://github.com/bheectory/first-project-mini-game-counter-Terminator-.git
when i press reset i want it to change all values to reset like when we refresh the page as we starting fresh. does anyone know what to put inside the bam function to make that happen please.
#how to edit this so high score record also changes when i press on reset
1 messages · Page 1 of 1 (latest)
You have to save it somewhere
like have to attach it to some html element and then use it by get elementbyid?
ohh idk whats that but i will try to figure that out
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Basically allows you to preview html/js
You have to save it so you can access it on rerun
That's why databases are good
Weren't they asking to help with the reset button?
You want the code to reset everything, like it does when you refresh the page, when you press the reset button, right?
https://jsfiddle.net/nhva42yf/
css seems a bit fcked up in this one but hope other elements remaining same here
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
yeah when i refresh the page everything goes back to 0
when i press save score it does that also
but puts a value below
so that button changing value two places
but the reset button only changing the counter
but not making the high score change
You'd change all the elements to have nothing in them
countStr = count + " / "
saveEl.textContent += countStr
These two lines handle changing the previous high scores values
i was trying to set the variable whioh holds the high score value to 0 or blank
so just add that line?
You can copy the saveE1 line to the bam() function
But set it to be an assignment to this: Previous High Scores 🥇:
So, use = instead of +=
And these two lines aren't necessary in the function either:
countStr = count
countStr.textContent = countStr
i used this and now its logging the 0 😮
so its better than before
yeah this was me trying things to make it work....
which failed
im too new to this lol
function save() {
/* these two are the lines you borrowed */
countStr = count + " / "
saveEl.textContent += countStr
count = 0
kills.textContent = count
}
function bam() {
count = 0
kills.textContent = count
/* You can just set saveE1.textcontent = "Previous high scores:" if you want a full reset */
/* These lines don't do anything */
countStr = count
countStr.textContent = countStr
}
so do this inside the bam then?
Commented some things for you as an example
oh woah thanks so much let me try to put things where you said
You only need to add 1 line to the bam() function to get what you want
To wipe the high score list as well
Need to change this: saveEl.textContent += countStr to be an assignment (=) instead of an append (+=) and add that to the bam() function you have
You have the original text from that here:
You can copypaste that into a string to assign to the saveE1.textContent
This line: let saveEl = document.getElementById("save-El") gets the element with ID save-El, which is the Previous High Scores box
Oh, that was a lowercase L instead of 1
My bad
function bam() {
count = 0
kills.textContent = count
saveEl.textContent += countStr
}
when i did this
its reseting the click count and also keep logging old value
+= will always add new text to the end of existing text
Wait..
So I don't have to do "string = string + 'text'"?
sorry for not understanding too well even after so clear instructions 😩
Or increase an integer
i will reread what you said
so have to set countStr with blank string first?
like countStr = " "
?
a = a + 1 == a += 1
string = string + text == string += text
= for assigning completely new values
+= for appending to existing values
whats a double == tho
oh so += means it will add the old one with it
Yes, you'll add the new value to the existing value
the codes your telling atleast making the high score numbers move lol
let string = "some text";
string += " additional text";
console.log(string);
>>> "some text additional text"
it was not budging before lol
yeah this i understand now i think! thanks
so two new strings
Use = for the saveEl.textContent line, and copypaste this into a string to set as the value:
Previous High Scores 🥇:
If you want a full reset
You do not need countStr, or count on that line at all
This is the only line you need to change: saveEl.textContent += countStr
Don't use +=
Change that to =
And instead of countStr
You'd use the text which is the original text from that element in HTML
ohhh so add the plain text from there 😮
Yup
Should look something like this:
saveEl.textContent = "Something"
so basically a hard reset 😮
But with the text from the HTML
Yup, you replace the entire content of the <h3>
Instead of appending to it (+=) like you do when you save a high score
omg it worked by hard reseting the texts and yet once i click its restarting just like new 🤤
your so pro huhu thank you so much hex!
i was trying to link it to the counter value which showing on top was the mistake i was making 😩
but had no idea we can also hard reset a result just by typing the exact same thing there 😮
your solution was so less painless and more easier than all that huhu
amazing
;) If you want to make the code fancier, you already get the save-El textContent, you could set a new let to be that as the value, and use that variable instead
let saveEl = document.getElementById("save-El")
This line
You can add a new let old_content = variable.textContent on that line :)
ohhh 😮
And instead of the string, you'd use the new let you made
and damm codes are looking so much more colorful in your side tho
But, your coding is using camelCase
So might want to use that naming scheme for your code
I used a screenshot from the jsfiddle
!formatting js
If you want fancy code formatting in Discord
ahh so many ways to do the same thing 😮
i thought i was using camel one but guess its pascal
havent heard of that one yet
Yeah, you were
My bad
PascalCase is both capitalized
camelCase is the second part
ohh lol sorry didnt see you edited it my bad!
snake_case is underscore separated
oh wait i think i remember we have to use pascal casing for some thing also but forgot for what its supposed to be used for lol
must be for some array creation or maybe object making idk 😩
They all work the same though, just makes code look different
You can mix and match
its just for uniformity
But it's easier to read if you stick to one naming scheme
I use snake_case myself
damm i just used that thing once for pasting only so did not noticed it was so colorfull xD
ahhh yeah this one looks more like software dev kinda style haha
everything having underscore to it
Discord can do that as well
let kills = document.getElementById("kills");
let reset0 = document.getElementById("reset0")
let saveEl = document.getElementById("save-El")
let count = 0
var countStr
function killFunc() {
count += 1
kills.innerText = count
}
function save() {
countStr = count + " / "
saveEl.textContent += countStr
count = 0
kills.textContent = count
}
function bam() {
count = 0
kills.textContent = count
countStr = count
countStr.textContent = countStr
}
oh 😮
how you do this
discord also have inbuilt editor then?
or we have to install something
this?
Can do html as well
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
ohh 😮
You'd change the language to match what you use
!formatting html
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
js for javascript
py for python
html for html
cpp for c++
it still wont budge lol
!formatting js
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
You don't use the command, hahah
!formatting html
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
```html
codehere
```
Hold on
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
!reveal
```html
<!doctype html>
<html>
<head>
<title>HTML highlighting</title>
</head>
<body>
<div>Different elements get also highlighted</div>
<ul>
<li>Element</li>
<li>Element2</li>
</ul>
</body>
</html>
```
you teaching so many stuffs
Fancy quotes are >
test
Fancy
Gotta have a space before the text
!reveal
> Fancy
Fancy
Please help me with my code 🥺
lol sorry for taking away hex for so long xD
thank you hex for taking out so much of your time to teach so many cool stuffs bro!
your amazing huhu
alex wants you too xD
Yeah bae