I am beginning Javascript learning, and am stumped on my first function. Spelling it out for my own sake, here is what I am try to achieve:
declare variables: color and primary
set color equal to the id "color" and grab the input value
set primary equal to one of two strings based on if color's value is either red, blue, or yellow
display primary in the p with id "answer"
I don't get a output. I suspect I should be using something in place of .value, and maybe the or statement is not correct. Would someone please give me a few pointers? I would greatly appreciate it. Here is the code:
<div>
Color:<input id="color" />
<p>Primary Color?</p>
<button onclick="myFunction1()">Click</button>
<p id="answer"></p>
<script>
function myFunction1()
{
var color,primary;
color=document.getElementById("color").value;
primary=(color="red"||"blue"||"yellow")?"It is a primary color":"Not a primary color";
document.getElementById("answer").innerHTML=primary;
}
</script>
</div>