#how to edit this so high score record also changes when i press on reset

1 messages · Page 1 of 1 (latest)

languid shell
unique lily
#

You have to save it somewhere

languid shell
#

like have to attach it to some html element and then use it by get elementbyid?

rapid mason
#

Could you host that on jsfiddle for example?

#

Would help debugging the code as well

languid shell
#

ohh idk whats that but i will try to figure that out

rapid mason
languid shell
#

sorry im new so not sure how to share codes 😩

#

thank you!

rapid mason
#

Basically allows you to preview html/js

unique lily
#

That's why databases are good

rapid mason
#

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?

unique lily
#

OH

#

They wanted to edit

#

My bad

languid shell
#

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

rapid mason
#

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

languid shell
#

i was trying to set the variable whioh holds the high score value to 0 or blank

#

so just add that line?

rapid mason
#

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
languid shell
#

so its better than before

languid shell
#

which failed

#

im too new to this lol

rapid mason
#
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
}
languid shell
rapid mason
#

Commented some things for you as an example

languid shell
#

oh woah thanks so much let me try to put things where you said

rapid mason
#

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

languid shell
#

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

rapid mason
#

+= will always add new text to the end of existing text

unique lily
#

So I don't have to do "string = string + 'text'"?

languid shell
#

sorry for not understanding too well even after so clear instructions 😩

rapid mason
#

Or increase an integer

languid shell
#

i will reread what you said

languid shell
#

like countStr = " "

#

?

rapid mason
rapid mason
unique lily
#

OH

#

Damn

languid shell
rapid mason
#

Strict equals

#

Means they're the same thing

languid shell
rapid mason
#

Yes, you'll add the new value to the existing value

languid shell
#

the codes your telling atleast making the high score numbers move lol

rapid mason
#

let string = "some text";

string += " additional text";

console.log(string);
>>> "some text additional text"
languid shell
#

it was not budging before lol

languid shell
#

so two new strings

rapid mason
#

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

languid shell
rapid mason
#

Yup

languid shell
#

woaah okay lemme try

#

and thank you so much for explaining it like to a baby!

rapid mason
#

Should look something like this:
saveEl.textContent = "Something"

languid shell
rapid mason
#

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

languid shell
#

your so pro huhu thank you so much hex!

languid shell
#

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

rapid mason
#

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

languid shell
#

ohhh 😮

#

so we can comeback to that variable if we need to anytime

rapid mason
#

You can add a new let old_content = variable.textContent on that line :)

languid shell
#

ohhh 😮

rapid mason
#

And instead of the string, you'd use the new let you made

languid shell
rapid mason
#

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

rare vectorBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```js
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

rapid mason
#

If you want fancy code formatting in Discord

languid shell
languid shell
#

havent heard of that one yet

rapid mason
#

Yeah, you were

#

My bad

#

PascalCase is both capitalized

#

camelCase is the second part

languid shell
#

ohh lol sorry didnt see you edited it my bad!

rapid mason
#

snake_case is underscore separated

languid shell
languid shell
rapid mason
#

They all work the same though, just makes code look different

languid shell
#

ohh

#

so there is no rule in coding

rapid mason
#

You can mix and match

languid shell
#

its just for uniformity

rapid mason
#

But it's easier to read if you stick to one naming scheme

languid shell
#

ahh so you use which one then?

#

you also stick with one?

rapid mason
#

I use snake_case myself

languid shell
languid shell
#

everything having underscore to it

rapid mason
#

Discord can do that as well

languid shell
#

woot? 😮

#

on its own?

rapid mason
#
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
}
languid shell
#

oh 😮

#

how you do this

#

discord also have inbuilt editor then?

#

or we have to install something

languid shell
rapid mason
#

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>
languid shell
#

<!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>

rapid mason
#

Discord got code blocks and syntax highlighting

#

!formatting html

rare vectorBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```html
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

languid shell
#

ohh 😮

rapid mason
#

You'd change the language to match what you use

languid shell
#

!formatting html

rare vectorBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```html
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

languid shell
#

<!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>

rapid mason
#

js for javascript
py for python
html for html
cpp for c++

languid shell
#

it still wont budge lol

rapid mason
#

Use backticks

#

`

languid shell
#

!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>

rare vectorBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```js
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

rapid mason
#

You don't use the command, hahah

languid shell
#

!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>

rare vectorBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```html
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

rapid mason
#

```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>
languid shell
#
<!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>
rare vectorBOT
languid shell
#

woaah broo

#

it working 😮

#

colors 🤤

#

finally

#

on discord huhu

#

damm

rapid mason
#

If you use only one backtick

#

You can do one line quotes

languid shell
#

you teaching so many stuffs

rapid mason
#

Like this

#

Or if you want something like this instead

languid shell
#

test

#

test

#

ow two also does same

rapid mason
#

Fancy quotes are >

languid shell
#

test

rapid mason
#

Fancy

languid shell
#

test

#

heh

rapid mason
#

Gotta have a space before the text

rapid mason
rare vectorBOT
languid shell
#

Fancy

unique lily
#

Please help me with my code 🥺

languid shell
#

test

#

ayyy

languid shell
#

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

unique lily
#

Yeah bae