samedi 28 décembre 2019

Javascript Functions/ innerHTML

So I'm trying to create a function that when the user clicks on a button or whereever I use the onclick method my problem is I have zero IDEA why my function won't work. I'm like 90% sure it worked yesterday and all I did was turn on my macbook......So I can get document.........innerHTML to work abstractly or in a void....but when I added it to this function it stopped working....I'm sure I did something I'm just not sure what.

    const insurances = ["amica", "travelers","national general","infinity","cincinatti"];

Honestly the only thing I can think that I changed was I made the insurance array a const instead of defining that inside the function but I can't imagine that's my issue.

   '''
   function cashBack1() {
    var amount=1;
    var statement = "Congratulations you just qualified for up to!! $";
    var insurance= document.getElementById('insurance').value;

    insurance = insurance.toLowerCase;

    amount = !insurances.includes(insurance) ? "$200" : "$300";

    alert("");
    document.getElementById('lilDiv').innerHTML = statement + amount;
  } 
  '''

My second problem is I can't get my and or statements right.....if you notice

     '''
    amount = !insurances.includes(insurance)? "200" :"$300";
    '''

I'm attempting to get it to an if statement but I started following vs code's suggestions lol. Here's the original version of the function

    '''
    function cashBack() {
      var amount=1;
      var statement = "Congratulations you just qualified for up to!! $";
      var insurance= document.getElementById('insurance').value;
      insurance = insurance.toLowerCase;
      if(!insurances.includes(insurance)){
      amount = "$200";
      }else {
      amount = "$300";
    } 
    alert("");//I added this alert just to see if it's making down to this part of the code..
             // It's not......
    document.getElementById("lilDiv").innerHTML = statement + amount;
     }
   '''

So I guess in conclusion this is a double part question. I need help in properly forming my if statement so I can get it to check if the user entered on of the target companies and they receive 300 cash back shown in an empty div.....if it isn't it should state that they receive 200 cash back. Help! THANKS IN ADVANCE

Aucun commentaire:

Enregistrer un commentaire