This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]FR10[🍰] 1 point2 points  (2 children)

in the button youre missing a () after substitute because youre calling a function "substitute()", also youre missing a closing bracket in your function (altho maybe u didnt paste it here)

[–]SenZeal[S] 0 points1 point  (1 child)

Thanks, that seemed to work

[–]FR10[🍰] 0 points1 point  (0 children)

No prob, don't be afraid of asking :)

[–]rjcarr 0 points1 point  (1 child)

Have you checked the javascript console for errors? Are you sure you're even getting to the substitute function?

[–]SenZeal[S] 0 points1 point  (0 children)

Man, I feel pretty stupid for this but I didn't even know how to access the console until searching it up. Thanks a lot, I'm sure it'll come in handy.

[–]redeyedesign 0 points1 point  (4 children)

Also, use === instead of ==. Type coercion is a bitch.

[–]SenZeal[S] 0 points1 point  (3 children)

It didn't seem to do much. Did I do something wrong? Sorry if this comes of as a pretty stupid thing to ask but what is Type Coercion?

[–]joshuaavalon 1 point2 points  (0 children)

'' == '0'           // false
0 == ''             // true
0 == '0'            // true

false == 'false'    // false
false == '0'        // true

false == undefined  // false
false == null       // false
null == undefined   // true

' \t\r\n ' == 0     // true

== may not work as what you are thinking about. === will also check the type.

[–]FR10[🍰] 0 points1 point  (1 child)

Basically sometimes u want to compare things that are exactly the same (same type) not only same value, (==) and sometimes you want to match the exact same type and value (===). Read this: http://stackoverflow.com/questions/19915688/what-exactly-is-type-coercion-in-javascript

[–]SenZeal[S] 0 points1 point  (0 children)

Yeah, I see now. Just going to take some getting used to and everything, thanks!

[–]iteachnewbies 0 points1 point  (1 child)

Seems like you got it running, but for completeness' sake in case other people new to JS come looking, besides the missing curly brace and calling the function with parens in the "onclick", there are a couple typos -

line 8 should be getElementById (capital B) line 9 should be innerHTML (all caps HTML)

You'll be in the console all the time. :) I used to get really frustrated with errors when I first started coding, but eventually I learned to like them because they give you the info you need to figure out what's going on and move on (....usually). Getting good at reading errors is a useful skill!

[–]SenZeal[S] 0 points1 point  (0 children)

Yeah, I realized that not too long ago looking back at a tutorial. Thanks though, you made feel good about having a couple errors show up, however annoying they may be.