lundi 27 septembre 2021

issue with scope from 2 javascript statements

I have a question about plugging the results of the for statement into the If statement. it says bill is not defined, but it is defined in the for statement. i know this has something to do with scope. but i am still new to coding javascript so i wanted to know how can i make it work"?

the code is:

'use strict';

const bills = [125, 555, 44]

for (var i=0; i< bills.length; i++) {
  let bill = bills[i]
  console.log(bill)
}

if(bill >= 50 && bill<= 300  ) {
  let tip = bill *.15
} else {
  let tip = bill *.20
}

Aucun commentaire:

Enregistrer un commentaire