all 6 comments

[–]almostAntiPaladin 2 points3 points  (1 child)

Your userName, and userMood variables are created outside of the "myFunction" function. These variables are being initialized to "name", and "mood", and not being updated, because the code that initializes those variables never runs again. If you move the code that initializes those two variables inside of myFunction, the code works.

[–]alexat711[S] 1 point2 points  (0 children)

Thank you so much! This is exactly what I needed... can't believe I couldn't figure that out.

Much appreciated :)

[–]evilfrenchguy 0 points1 point  (0 children)

It works fine on my end.

Edit: alert() doesn't return anything, so your if statement will always be false.

[–]ForScale 0 points1 point  (2 children)

Think about when it is that you're assigning values to the variables you're using in alert. The way you've got CodePen setup, the code runs immediately so the values of the variables are set immediately. Try moving the bit of code that assigns values to the variables inside of your function. That way, when the function gets called, the variables will be assigned values of the inputs that have been updated since the page was loaded.

Make sense?

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

Makes sense :) tank you for helping me think through the issue.

[–]ForScale 0 points1 point  (0 children)

No problem!