Please a javascript project

Please a javascript project

<!DOCTYPE html>

<!DOCTYPE html>

<html lang="en">

 <head>

  <meta charset="UTF-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <meta http-equiv="X-UA-Compatible" content="ie=edge" />


  <title>Mini App</title>


  <style>

   body{

    background: #fff;

   }

  </style>

 </head>

 <body>

  <h2>GetWet App</h2>

  <div class="select-currency select">

   <select class="select-text">

    <option value="">disabled</option>     

    <option value="">Selected</option>

    <option value="">Choose Currency</option>


   </select>

  </div>

  <button class="btn">Convert</button>

  <div class="conversion mdc-elevation--z3">

    

  </div>

  <div class="message">

    

  </div>

  <script>

    

   const currencies = [{

    id: 'USD', name: 'US Dollars'

   }, {

    id: 'UGX', name: 'Ugandan Shillings'

   }, {

    id: 'KES', name: 'Kenyan Shillings'

   }, {

    id: 'GHS', name: 'Ghanian Cedi'

   }, {

    id: 'ZAR', name: 'South African Rand'

   }];

    

      const apiBase = 'https://free.currencyconverterapi.com/api/v6/';

   const api = (currency) => `

    ${apiBase}convert?q=${currency}_NGN&compact=ultra

 `;

    

   const toast = (msg) => {

    const toastr = document.querySelector('.messages');

    if(!toastr) return;

     

    toastr.textContent = msg;

    if(!toastr.classList.contains('on')) {

     toastr.classList.add('on');

    }

   };

    

   const doneToasting = () => {

    const toastr = document.querySelector('.messages');

    if(!toastr) return;

     

    toastr.textContent = '';

    toastr.classList.remove('on');

   };

    

   const conversionSucceeded = (apiResponse) => {

    if(!apiResponse) {

     toast(`nothing to display ...`);

     return;

    }

     

    const [value] = Object.values(apiResponse)

     

    const btn = document.querySelector('button');

    btn.removeAttribute('disabled');

     

    const display = document.querySelector('.conversion');

    const formatter = new Intl.NumberFormat(

     'en-NG', { style: 'currency', currency: 'NGN' }

    );

     

    display.textContent = formatter.format(value);

    doneToasting();

   };

    

   // declare populateCurrencies here    

    

   const getSelectedCurrency = () => {

    // here, determine and return the selected value 

    // of the SELECT element

   };

       

   const convert = (event) => {

    toast(`preparing to convert ...`);

     

    const btn = event ? 

       event.target : document.querySelector('button');

     

    const selected = getSelectedCurrency();

     

    if(!selected || selected.trim() === '' 

      || !currencies.map(c => c.id).includes(selected)) return;

     

    btn.setAttribute('disabled', 'disabled');

    toast(`converting ...`);

     

    const endpoint = api(selected);

     

    // make a GET fetch call to the endpoint

    // variable declared above, convert the response to JSON,

    // then call conversionSucceeded and pass the JSON data to it

     

   };

    

   const startApp = () => {

    // call populateCurrencies here

     

    // add a click listener to the button here

   };


   startApp();

  </script>

 </body>

</html>

javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

The essential JavaScript concepts that you should understand

The essential JavaScript concepts that you should understand - For successful developing and to pass a work interview

Data Types In JavaScript

JavaScript data types are kept easy. While JavaScript data types are mostly similar to other programming languages; some of its data types can be unique. Here, we’ll outline the data types of JavaScript.

JavaScript Memory Management System

The main goal of this article is help to readers to understand that how memory management system performs in JavaScript. I will use a shorthand such as GC which means Garbage Collection. When the browsers use Javascript, they need any memory location to store objects, functions, and all other things. Let’s deep in dive that how things going to work in GC.

Create a Line Through Effect with JavaScript

In this post we are going to create an amazing line through effect, with help of CSS and lots of JavaScript. So, head over to your terminal and create a folder LineThroughEffect. Create three files -index.html, main.js and styles.css inside it.

Grokking Call(), Apply() and Bind() Methods in JavaScript

In this article, we will have a look at the call(), apply() and bind() methods of JavaScript. Basically these 3 methods are used to control the invocation of the function.