mercredi 21 septembre 2016

Javascript/jQuery code does not run past first if/else statement [duplicate]

This question already has an answer here:

I have made a basic math game sort of thing, where after you click the "check" button, it runs the if/else statements. Even if you have all the right answers it will not go past the first if/else. I have tried changing the if statements from if/else to just if statement. Also it will not run the code for if you get a question wrong.

I have added more code to this but I will highlight the necessary parts.

<DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb">
<head runat="server">
  <meta charset="utf-8"/>
  <link rel="stylesheet" href="http://ift.tt/1jAc5cP" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  <link href='http://ift.tt/2aTT5TI' rel='stylesheet' type='text/css'>
<script src="http://ift.tt/29HnGIn"></script>
<script>
    $(document).ready(function () {
        $('#Button1').click(function () {
            var T1value = $('input[name=Text1]').val();
            if (T1value == "8") {
                $('#Text1').addClass('correct'); }
            if (T1value != "8") {
                $('#Text1').addclass('incorrect'); }
            var T2value = $('input[name=Text2]').val();
            if (T2value == "33") {
                $('#Text2').addClass('correct'); }
            if (T2value != "33") {
                $('#Text2').addclass('incorrect'); }
            var T3value = $('input[name=Text3]').val();
            if (T3value == "9") {
                $('#Text3').addClass('correct'); } 
            if (T3value != "9") {
                $('#Text3').addclass('incorrect'); }
            var T4value = $('input[name=Text4]').val();
            if (T4value == "16") {
                $('#Text4').addClass('correct');}
            if (T4value != "16") {
                $('#Text4').addclass('incorrect'); }
            var T5value = $('input[name=Text5]').val();
            if (T5value == "500") {
                $('#Text5').addClass('correct');}
            if (T5value != "500") {
                $('#Text5').addclass('incorrect');}
            var T6value = $('input[name=Text6]').val();
            if (T6value == "225") {
                $('#Text6').addClass('correct'); }
            if (T6value != "225") {
                $('#Text6').addclass('incorrect');}
            var T7value = $('input[name=Text7]').val();
            if (T7value == "4") {
                $('#Text7').addClass('correct');} 
            if (T7value != "4") {
                $('#Text7').addclass('incorrect'); }
            var T8value = $('input[name=Text8]').val();
            if (T8value == "30") {
                $('#Text8').addClass('correct');
            } if (T8value != "30") {
                $('#Text8').addclass('incorrect');}
            var T9value = $('input[name=Text9]').val();
            if (T9value == "8") {
                $('#Text9').addClass('correct');
            } if (T9value != "8") {
                $('#Text9').addclass('incorrect');}
            var T10value = $('input[name=Text10]').val();
            if (T1value == "4") {
                $('#Text10').addClass('correct');
            } if (T10value != "4") {
                $('#Text10').addclass('incorrect');}
        });
        });
</script>
<title></title>
<style type="text/css">
    #aRow1 {
        padding: 15px 15px 15px 15px;
        background-color: #141514;
        color: white;
    }
    .auto-style1 {
        width: 252px;
    }
    .correct {
        border-color: green;
        border-style: solid;
        border-width: 3px;
    }
    .incorrect {
        border-color: red;
        border-style: solid;
        border-width: 3px;
    }
    body {
        padding-bottom: 20px;
        padding-left: 30px;
        padding-right: 30px;
        padding-top: 20px;
        font-family: Roboto, sans-serif;
    }
    .body-content {
        padding-left: 15px;
        padding-right: 15px;
    }
    .dl-horizontal dt {
        white-space: normal;
    }
    input,
    select,
    textarea {
        max-width: 280px;
    }
    .hide {
        background-color: white;
    }
    #table1 {
        background-color: #141514;
        padding: 15px 15px 15px 15px;
        color: white;
        align-items: center;
    }
    #table1, 
    input {
        background-color: #141514;
        border-bottom-color: #4e5456;
        border-left-color: #141514;
        border-right-color: #141514;
        border-top-color: #141514;            
    }
    .Button {
        background-color: #259BBD;
        width: 128px;
    }
    .auto-style2 {
        width: 38%;
        margin-right: 639px;
    }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="row">
    <figure class="col-sm-4" >
        <section id="Table1">
    <table>
        <tr>
            <td class="auto-style1">3x + 3 = 27&nbsp;&nbsp;&nbsp; x = </td>
            <td id="TT1">
                <input id="Text1" type="text" name="Text1"/></td>
        </tr>
        <tr>
            <td class="auto-style1">67 + ? = 100&nbsp;&nbsp;&nbsp; ? =</td>
            <td>
                <input id="Text2" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">81 / 9 =</td>
            <td>
                <input id="Text3" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">4 * 4 =</td>
            <td>
                <input id="Text4" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">996 + 4 - 500 =</td>
            <td>
                <input id="Text5" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">50% of 450 =</td>
            <td>
                <input id="Text6" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">4x + 4 = 20&nbsp;&nbsp;&nbsp; x = </td>
            <td>
                <input id="Text7" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">16 + 7 * (5 -3) =</td>
            <td>
                <input id="Text8" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">15 - 7 =</td>
            <td>
                <input id="Text9" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">16 / 4 =</td>
            <td>
                <input id="Text10" type="text" /></td>
        </tr>
        <tr>
            <td class="auto-style1">&nbsp;</td>
            <td>
                <input id="Button1" class="Button" type="button" value="Check" /></td>
        </tr>
    </table>
        </section>
    </figure>
    <figure class="col-sm-4"></figure>
    <figure class="col-sm-4">
    </figure>
 </form>
 </body>
 ``</html>

Aucun commentaire:

Enregistrer un commentaire