Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3539
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T18:32:31+00:00 2022-06-02T18:32:31+00:00

need help understanding why only the one condition is showing upp [duplicate]

  • 0

[ad_1]

hey i need help with this code. i keep getting only the first image (return document.getElementById("output").src = "img/violett1.jpg";) no matter what number i type in or what date i choose only the condition written in the if-statement is showing up.

i would appreciate if someone can correct my code or show me an alternative way of solving this problem

This is the code that i have written.

<script>
    window.onload = start;
    
            var arrT = [4.9, 6.1, 6, 8.2, 9.4, 8, 8.8, 12, 14.8,   11.7, 11.7, 9.4, 7.6, 7.8, 12.3, 12.8, 11, 8.9, 7.7, 7.5, 9.3, 10.4, 9.2, 7.3, 8, 11.3, 11.7, 15.7, 21.1, 17.9, 16.7];

            
            function start() {
                
                document.getElementById("btnShowColor").onclick = showColor;        
            }
            function showColor (){
                var image = findColor("arrT");
    
                document.getElementById("output").innerHTML = image;
                }

            
            function findColor() {
                var chosenDate = parseFloat(document.getElementById("lstDate").value);
                var D = parseFloat(document.getElementById("txtTemprature").value);
                var T = arrT[chosenDate];

                
            
                if(D > (T-7) ) {
                    return document.getElementById("output").src = "img/violett1.jpg";
                    
                }

                else if( -7 > D > (T-4) ){ 
                    return document.getElementById("output").src = "img/brown.jpg";
                
                }
                else if(-4 > D > (T-1) ){
                    return document.getElementById("output").src = "img/green.jpg";
                }
                else if( -1 > D > (T+1) ){
                    return document.getElementById("output").src = "img/pink.jpg";
                }
                else if(1 > D > (T+4) ){
                    return document.getElementById("output").src = "img/black.jpg";
                }
                else if(-4 > D > (T+7) ){
                    return document.getElementById("output").src = "img/orange.jpg";
                }
                else {
                    return document.getElementById("output").src = "img/red.jpg";
                }
            }
      

</script>
<body>
      <input type="text"  id="txtTemprature"  > 
                <br>
    
                
                <select id="lstDato">
                    <option>choose date</option>
                    <option value=0>01.31.1917</option>
                    <option value=1>02.31.1917</option>
                    <option value=2>03.31.1917</option>
                    <option value=3>04.31.1917</option>
                    <option value=4>05.31.1917</option>
                    <option value=5>06.31.1917</option>
                    <option value=6>07.31.1917</option>
                    <option value=7>08.31.1917</option>
                    <option value=8>09.31.1917</option>
                    <option value=9>10.31.1917</option>
                    <option value=10>11.31.1917</option>
                    <option value=11>12.31.1917</option>
                    <option value=12>13.31.1917</option>
                    <option value=13>14.31.1917</option>
                    <option value=14>15.31.1917</option>
                    <option value=15>16.31.1917</option>
                    <option value=16>17.31.1917</option>
                    <option value=17>18.31.1917</option>
                    <option value=18>19.31.1917</option>
                    <option value=19>20.31.1917</option>
                    <option value=20>21.31.1917</option>
                    <option value=21>22.31.1917</option>
                    <option value=22>23.31.1917</option>
                    <option value=23>24.31.1917</option>
                    <option value=24>25.31.1917</option>
                    <option value=25>26.31.1917</option>
                    <option value=26>27.31.1917</option>
                    <option value=27>28.31.1917</option>
                    <option value=28>29.31.1917</option>
                    <option value=29>30.31.1917</option>
                    <option value=30>21.31.1917</option>

                </select>
                <button id="btnShowColor">showColor</button>
                <img id="output">
                
                
            

                
                
                
</body>

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8087 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1871 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1957 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.