0

How does Console.log help in debugging? Can you give me an example too?

I was curious to know what us the difference between console.log and document.write so I searched it and found this post https://www.sololearn.com/discuss/262481/?ref=app here ppl have mentioned that they use it for debugging so how do they actually do it?

12th Jun 2017, 5:46 PM
_Retr0/-
_Retr0/- - avatar
2 odpowiedzi
+ 3
Imagine this scenerio: *This is in c#, but its the same thing for Javascript* private int playerHp; void playerDie(){ if(playerHp <= 0) die(); } Hm.. this isn't working. So I do: Console.Write(playerHp); Output: 100. Maybe I realize: The Hp never went down?! Ohhh I forgot to do playerHp -= enemyDmg; When he was supposed to take damage. So, it allows you to see values just like a debugger to help you narrow down the problem. You could use alert() too for Javascript. I do this kind of thing all the time for debugging. Very useful if you're stuck on a bug.
12th Jun 2017, 6:02 PM
Rrestoring faith
Rrestoring faith - avatar
0
Check out this unit test method: if function return value equals to expected result, console.log(" test has passed."); if function return value not equals to expected result, console.log(" test has failed."); https://code.sololearn.com/W2n6kfeQixs1/#html
12th Jun 2017, 8:16 PM
Calviղ
Calviղ - avatar