I just started learning Javascript. For a beginners project I'm making a quiz-guide to find out which South Park character you are. But I have some problems making it work. Here are some pieces of my code:
In my HTML-document the code looks like this:
<form name="characterform">
<p>What kind of food do you like to eat?</p>
<ul>
<li><input type="radio" name="1" value="" id="radio11" />Pizza</li>
<li><input type="radio" name="1" value="" id="radio12" />Chips and snacks</li>
<li><input type="radio" name="1" value="" id="radio13" />Health foods</li>
<li><input type="radio" name="1" value="" id="radio14" />Kosher</li>
<li><input type="radio" name="1" value="" id="radio15" />Powdered donut pancake surprise</li>
<li><input type="radio" name="1" value="" id="radio16" />Anything, as long as it's cheap</li>
</ul>
<input type="button" name="button" value="Calculate" id="button" onClick="start()" />
</form>
In my script-document I begin by creating my variables and use if-statements to change them, like this:
function start(){
if(document.characterform.radio11.checked)
cartman += 5;
kyle += 5;
stan += 5;
kenny += 5;
butters += 5;
Finally I use if-statements to get a result:
if(cartman > kyle && cartman > stan && cartman > kenny && cartman > butters)
alert("Cartman! " + "\n" + cartman + "\n" + kyle + "\n" + stan + "\n" + kenny + "\n" + butters);
else if(kyle > cartman && kyle > stan && kyle > kenny && kyle > butters)
alert("Kyle! " + "\n" + cartman + "\n" + kyle + "\n" + stan + "\n" + kenny + "\n" + butters);
else if(stan > cartman && stan > kyle && stan > kenny && stan > butters)
alert("Stan! " + "\n" + cartman + "\n" + kyle + "\n" + stan + "\n" + kenny + "\n" + butters);
else if(kenny > cartman && kenny > stan && kenny > kyle && kenny > butters)
alert("Kenny! " + "\n" + cartman + "\n" + kyle + "\n" + stan + "\n" + kenny + "\n" + butters);
else
alert("Error");
I've done this with all my radio-buttons. The problem is that no matter which radio button is selected, the result is always the same: kyle. In fact, when looking at the print-out of the numbers it seems that Cartman is the only variable that changes. The other four variales are exactly the same, no matter what, with kyle getting the most points.
All of the script-code is in the start() function, except the creating of the variables.
I've searched alot for an answer, but I haven't found anyone with the same problem - so I'm guessing there's an easy solution to my problem. I hope someone here can help me understand this.
(cartman > kyle)...