Uncaught Reference Errors

Joined
Oct 9, 2022
Messages
1
Reaction score
0
// Step 1:
// a. create a new variable named "pillCost".


// b. set its value to be the product of pill count and pill price.


// c. get the values of pill count and pill price by calling the appropriate helper functions.

function getPillPrice() {
let pillPrice = parseFloat(document.getElementById("pill-price").value);
console.log("pill-price: " + pillPrice);
return pillPrice;
}

function getPillCount() {
let pillCount = parseFloat(document.getElementById("pill-count").value);
console.log("pill-count: " + pillCount);
return pillCount;
}

function getPillCost() {
let pillPrice = parseFloat(document.getElementById("pill-price").value);
let pillCount = parseFloat(document.getElementById("pill-count").value);
let pillCost = pillPrice * pillCount;
console.log('pillCost: ' + pillCost);
return pillCost;
}

// d. dump the value of pillCost in the console so you can see what's going on.
// To do this, uncomment the line below -- after you've done (1a) and (1b).
// console.log("pillCost: " + pillCost);
// e. open your devtools console to see the message.i

When I call the function getPillCost() in the console it said uncaught reference error:getPillCost is undefined but I don't know why it had this problem.
 
Joined
Jul 3, 2022
Messages
93
Reaction score
23
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title></title>
    <style>
    button,input,label{
    margin: 10px;
    text-align: center;
    cursor: pointer;
    }
    </style>
   </head>
  <body>   
  <fieldset>
  <legend>Dealer's calculator</legend>
  <label for="pill_price">Pill price<input type="text" id="pill_price" placeholder="Price" /></label>
  <label for="pill_count">Pill count<input type="text" id="pill_count" placeholder="Count" /></label>
  <button>Calculate</button>
  </fieldset>
 
      <script>
// a. create a new variable named "pillCost".
// b. set its value to be the product of pill count and pill price.
// c. get the values of pill count and pill price by calling the appropriate helper functions.
// d. dump the value of pillCost in the console so you can see what's going on.
function getPillPrice() {/* c */
return parseFloat(document.getElementById("pill_price").value) || 0;
// ...or 0 if the value is empty
}

function getPillCount() {/* c */
return parseFloat(document.getElementById("pill_count").value) || 0;
// ...or 0 if the value is empty
}

/* a */
let pillCost = function() {/* b */
return getPillPrice() * getPillCount();
}

document.querySelector('button').addEventListener('click', function(){
/* d */
console.log( "pillCost: " + pillCost() );
});
   </script>
  </body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top