0

I'm making a basic usd converter for practice in html/javascript. However when I select the euro option it does the same as for the peso option.

<html>
    <head>
        <title>Currency Converter</title>
        <style>

        </style>
    </head>
    <body>
        <input id="amount"> </input>
        <p>usd Contverted to</p> 
        <p class="output"> </p>
        <select id="select"> <option value="1">Peso's</option> <option value="2">Euro's</option> </select>
        <p id="answer"> is </p>
        <input type="submit" value="Submit" onclick="run()"> 
        <script>
            function run() {
                var Amount = document.getElementById("amount").value;
                if (select = 1) {
                    document.getElementById("answer").innerHTML = "=-=-= " + Amount * 16.39  + "   =-=-=";
                } else if (select = 2) {
                    document.getElementById("answer").innerHTML = "=-=-= " + Amount * 0.9  + "   =-=-=";
                } else {
            }
        </script>
    </body>
</html>
1

3 Answers 3

1

You are not comparing select,you are setting it.

   if (select == 1) {
       document.getElementById("answer").innerHTML = ...
   } else if (select == 2) {
  • = -> setting a value
  • == -> comparing
Sign up to request clarification or add additional context in comments.

Comments

1

it should be select == 1 select=1 will always return true, because this way you are simply assigning a value, not checking for equality

Comments

0
  • You are not getting value of select
  • You are not comparing select value in if condition, make it as select == 1 and select == 2

Complete solution here

Change your javaScript function as below

function run() {
  var Amount=document.getElementById("amount").value;
  var select=document.getElementById("select").value;
  if (select == 1) {
    document.getElementById("answer").innerHTML = "=-=-= " + Amount * 16.39  + "   =-=-=";
  } else if (select == 2) {
    document.getElementById("answer").innerHTML = "=-=-= " + Amount * 0.9  + "   =-=-=";
  } else {
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.