My first Scrimba web weekly challenge: currency exchange
yubaraj singh
Posted on January 15, 2021
I am currently enrolled in Scrimba's frontend master. I liked the teaching practice of Scrimba as they have an interactive teaching environment.In addition, they are doing a web weekly challenge and this week was a challenge to make a currency exchange page. link to challenge: link
so in order to solve this problem, I use a javascript query selector to select the input value and assigning the value to a variable.
const OriginalCurrencyAmount=document.getElementById('original-currency-amount')
const currencyUnit=document.getElementById('original-currency-unit')
const newCurrency=document.getElementById('new-currency-unit')
const exchangeRate=document.getElementById('exchange-rate')
const button=document.getElementById('exchange')
After that, I had to make the button click work, so I added eventlistener in the button so when it is clicked then I will trigger a function to do the calculation and show the money exchange price.
button.addEventListener('click',function(){
})
After that, I checked if the value is filled in the text box for validation. If the user clicked without filling in all the values then it will display a message to fill all values.
if(OriginalCurrencyAmount.value ==="" || currencyUnit.value ==="" || exchangeRate.value ==="" || exchangeRate.value ===""){
document.getElementById('output-text').textContent=" please fill all values π°"
}
else
{ var exchange=OriginalCurrencyAmount.value * exchangeRate.value
document.getElementById('output-text').textContent=" your exchange rate of "+OriginalCurrencyAmount.value+ "π° "+currencyUnit.value+ " will be "+ exchangeRate.value +" " +newCurrency.value+" currency"}
So, if all the values are filled then it will calculate the money exchange value simply by multiplying the exchange rate with input currency value.
so here is my solution to the challenge.
link
Posted on January 15, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024