I want to use javascript to change the background colour within an IF statement?

Q: This is my code and its not working :(

A: hey. the first person who answered has it right - when comparing favcolor to a string in your if statements, you need to put the string in inverted commas (ie if (favcolor == 'purple'){//do this}. Otherwise, it thinks it is comparing to a variable called purple. your browser should recognise the name of most common colours, so you could actually adjust your program so that the user can type almost any colour and the background colour will change. see the code below:

almost any colour you can think of is covered here: orange, blue, black, white, grey, purple, pink, red, yellow, green, even things like darkblue and darkgreen, crimson, dodgerblue, aliceblue, springgreen.... as long as there's no space between two words, that is! here's a list of all the named colours: http://www.gb.nrao.edu/~cbignell/testcolors.html

Related items