0

so my code is about when I select the currency the price and symbol must change; if I chose USD $ and it already was in $ then nothing should change while If I chose LBP and the currency was in $ the price must be multiplied by 2000 and the symbol would change from $ to LBP, But the problem is that when I introduced this statement in JS the script stops on working (it was multiplying it by 2000):

function report(currencyy) {
  var price = document.getElementById("price");
  var symbol = document.getElementById("symbol");
  symbol = String(symbol);

  if (currencyy == "lbp") {
    if (symbol =="$") {
      symbol.innerHTML = "lbp";
      var text = price.textContent;
      var number = parseInt(text) * 2000;
      price.innerHTML = number;
    }
  }
}
<pre> <div class="card">
  <img class="imgcar" src="cars/402088-2020-land-rover-range-rover-velar.jpg" alt="Avatar" style="width:16em">
  <div class="container">
    <h4><b>Range Rover Velar</b><br><b>4 Doors</b><br><b> 5 Passengers</b> </h4>
    <p id="price">100</p><p id="symbol">$</p><p>/24hrs</p>
  </div>
</div>
</pre>

2 Answers 2

2

You should compare the content not the element. Also, not sure what you are trying to do with:

symbol = String(symbol);

Try

var price = document.getElementById("price");
var symbol = document.getElementById("symbol");

if (currencyy == "lbp") {
  if (symbol.textContent == "$") { //compare the content
    symbol.textContent = "lbp";
    var text = price.textContent;
    var number = parseInt(text) * 2000;
    price.textContent = number;
  }
 }
}
Sign up to request clarification or add additional context in comments.

Comments

0
<ng-template  [ngIf]="isStatusCode[j] === false">
   <img class="list-image"  (error)="changeImgSource($event)" [src]="getConfigProductImage(element['shrt-campaign-product'][0]['products']['product_images'])"   height="40"
   alt="productImage">
</ng-template>
<ng-template  [ngIf]="isStatusCode[j] === true">
   <img class="list-image"  (error)="changeImgSource($event)" src="/assets/images/loader.gif"  height="60" alt="noImage">
</ng-template>

2 Comments

@Darshan_Malani Hello, what language is this?
@FirasRihan Deat it's Angular language... do you have question now ?

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.