#random js question

65 messages · Page 1 of 1 (latest)

spare lava
#

Hey @unkempt rivet ,
Alright, I don;t fully understand how the game works lol,
But running some console.logs

highScore.innerHTML = `High Score: ${timer}`
                            console.log(highScore.innerHTML)
console.log($timer)

$timer is not defined, and that's creating he problems.
It's probably cause by your redefinition of variables on line 73
highScore = timer
But I'm not able to dig beyond that

Oh and by the way, you should use backticks instead of quotes

unkempt rivet
#

I don't see any redefinition on line 47 I am guessing u ment line 73
And u might be right , But if u try add anything in the .textcontent it still doesn't work

#

And about the backticks I fixed it

#

and timer is defined because its not $timer that is the value its timer , $ just lets me be able to use it in the backticks..

#

Thank you anyway!!

spare lava
#

I believe that the way you had written it would display "High score: ${timer}" as a string, and not the actual value of timer

#

unrelated, but on line 8 you have
let randomWidth it's not initialized?

unkempt rivet
spare lava
#

that part puzzles me, line 14-15
let highScore = document.getElementById("high-score") highScore = 0

unkempt rivet
#

Ye idk if the highScore = 0 was needed but I just set it to 0 because it will later be set to another number

#

I don't think it was needed

spare lava
#

basically, it sets the DOM element to 0. I think that's the problem.
You want two constants no?
1 is the DOM element, theother is the highscore number value

#

damn, debugging someone else's code is HARD 😄

unkempt rivet
unkempt rivet
spare lava
#

alright, I created this bit to show you

let highScoreEl = document.getElementById("high-score")
highScore = 0
timer = 350
highscore = timer
highScoreEl.textContent = `Highscore: ${timer}```
#

pasting it at the top, in your constants, so it displays on refresh

#

highScoreEl is the DOM element,
highScore is your value, a number,
I understand that you want to set the timescore to the timer value,
them we display that timer value in the DOM with textContent

#

now it's just a matter of finding where to put that logic in your code, but I need to take a break and have lunch lol

unkempt rivet
#

Bassicelly ye

spare lava
#

does taht make sense?

unkempt rivet
#

Im sure it make sense Just not my sense lol

#

Thanks for the help

#

bon appetit

spare lava
#

merci . good luck

unkempt rivet
#

ty

unkempt rivet
#

Can somebody else help me ?

spare lava
#

hey I'm back. Have you figured it out? I have

#

That snippet I gave you earlier? put the appropriate lines in your function line 74 and it'll work

unkempt rivet
#

O fuc*

#

I didn't see u answered mb

#

Which one are u talking about? @spare lava

spare lava
#

let highScoreEl = document.getElementById("high-score")
highScore = 0
timer = 350
highscore = timer
highScoreEl.textContent = `Highscore: ${timer}

unkempt rivet
#

Put all of that in 74?

spare lava
#

I put some comments for you to check what was changed

unkempt rivet
#

is this what u mean?

#

Because it doesn't seem to work for me

spare lava
#

don't forget to change the name of your getElelentbyID constants

unkempt rivet
#

I added the highscore = timer

unkempt rivet
#

I am not sure what is the difference

spare lava
#

check my scrim; it works

unkempt rivet
#

Ye ik

#

Here lemme send u an updated version of mine

#
Scrimba

Learn to code with interactive screencasts. Our courses and tutorials will teach you React, Vue, Angular, JavaScript, HTML, CSS, and more. Scrimba is the fun and easy way to learn web development.

#

ignore the hugeeeeeee link

#

@spare lava

#

I found what was cauesing the issue

#

is there a difference between this:
highScore.textContent = Highscore: ${timer}

and this:

        highScore.textContent = `Highscore: ${timer}`
#

with backticks ofc

#

it just does the thingy

#

NOO

#

IDK WHAT I DID

#

BUT IT FIXED It

#

AND UNFIXED IT

#

BUT IT DOESN"T WORK NOW

#

IDK HOW TO FIX IT

#

NOO

#

deprrestion

spare lava
#

Take a break then. Working frustrated doesn’t do any good. You’ll come back to it later and it’ll be alright

unkempt rivet
#

Ye I figured it out

#

Thank you for ur help Geoffrey