Plz i need help with declaring const variable

i want declare a variable using an arrow function

const populateCurrencies = () => {};//dis is wat i hav so far // declare populateCurrencies here

and also how to create an arrow function

let const populateCurrencies = () => {};

plz could u tell me why u hav d 'let' function

You could have use “var”, I just use “let” at a term for identifying a variable as a good habit because when I use it inside of a for loop it’s scope is contained within the for loop

ok thanks wat about if i want to call d populateCurrencies function back into another function like

const startApp = () => {
// calling the populateCurrencies here
};

To call a function you just need to do functionName() (or the name of the variable in which is stored)

Be just sure you declare your function before calling it

Just to note, if the arrow function is called from inside another function you can declare it after and it still works.

This works:

function ret() {
  log()
}

const log = () => {
  console.log('logging')
}

ret();

This does not work:

log();

const log = () => {
  console.log('logging')
}

<title>Mini App</title>

<style>
  body {
    background-color: white;
    margin: 15px;
  }
  .select {
    margin-top: 50px;
  }
  .conversion {
    margin: 25px 0 25px 0;
  }
  .btn{
    padding: 25px 50px 25px 50px;
  }
</style>

WandeCurrency

Choose Currency
Convert to Naira
<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>

i hav dis assignment dat i am trying to solve which its given me a headache really hav done some parts but i am trying to solve d JS

Do you have a specific question?

i am trying to create a `populateCurrencies` arrow function before the already declared `startApp` function.

and i am trying to create an OPTION element, to set its value to the item's id, and to set its text to the item's name, and then add the OPTION to the SELECT element

I’m not going to do your assignment for you unless you have some specific question I can’t help you.

What have you tried?
What doesn’t work?
Is there something specific you are not sure about how to do?

ok

wen i declared my populateCurrencies function my app clear away frm d screen

That is not a question.

However if your app stops working when you declare a function without even calling it, you most likely have a syntax error. Open up the browser console and look (Ctrl+Shift+I go to the console tab).

My brother, good evening sir.

Please i like to tell you i’m in the same hot sit as have been trying to get the code solved.
Have you made a way out? if yes, please share it sir

i have actually made it out. b ut haven t sub mitted yet

<title>Mini App</title>

<style>
  body{
    background-color: white	
      
      ;
    
    margin: 15px;
  }
  .select{
    margin-top: 50px;
  }
  
  
  
  
  .conversion{
    margin: 25px 0px 25px 0px;
  }
  .btn{
   width: 100%;
    padding: 20px;
    
  }
</style>

GanDollarz

choose currency:
</select>
  </div>
<button class="btn"> Convert here</button>
<div class="conversion mdc-elevation--z3"></div>
<div class="messages"></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
    var e = document.getElementById('select-text');
    var displaytext= e.options[e.selectedIndex].value;
    
  };
        
  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 populateCurrencies = () => {
   const [selectElement] = document.getElementsByTagName("select");

currencies.map((currency) => {
const option = document.createElement(‘option’);
option.setAttribute(‘value’, currency.id);
option.innerHTML = currency.name;
selectElement.appendChild(option);
});

  };
  
  
  
  const startApp = () => {
    // call populateCurrencies here
    populateCurrencies();
   // add a click listener to the button here
   
             doument.getElemntByClass('btn').addEventlistener('click', function(){
               convert(event);
             });
    
  };

  startApp();
</script>

hit me up @ brunoaugustine2@gmail.com
ive got answers

You guys do understand what the point of an assignment is right? It is far more valuable to try and fail a bunch than it is to copy paste code. Learn how to ask for help and guidance so you can do it on your own with the help of others.

I’m not a mod here and this is just my personal opinion. But what you are doing seems to go against the academic honesty principles FCC is run by and I don’t think this is the place for this type of thread. Again, just my opinion.