Can't find the error in the code? 6/7


#1

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return-ii?action=lesson_resume

The error message reads: “exepected function” but I can’t find the error…

```

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ’ + crustType + ’ crust topped with ’ + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(itemCount) * 0.06;
}

function getTotal() {
return getSubtotal(itemCount) + getTax(itemCount);
}

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);

console.log(getSubTotal(orderCount));

<do not remove the three backticks above>

#2

Hi @seanalexanderharris, do have a look at the comments inside the code:

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ' + crustType + ' crust topped with ' + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {   //<== this is correct, itemCount is used as parameter
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(itemCount) * 0.06; //<=== itemCount should be replaced with orderCount, you're calling the function getSubTotal() by passing an argument inside, the argument is orderCount.
}

function getTotal() {
return getSubtotal(itemCount) + getTax(itemCount); //<=== same here, itemCount should be replaced with orderCount, you're calling the function by passing an argument inside, the argument is orderCount. itemCount should not be used when calling functions.
}

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

console.log(getSubTotal(orderCount)); 

Add another console.log because:

The final instruction copied from the lesson:

On the last line of the program, call the getTotal function inside of a console.log statement to view the result.

You need console.log(getTotal());

Hope this helps. Cheers :slight_smile:



#3

Thanks. I understand your comments. However, when I’ve made the changes my code still doesnt’s seem to work and gives the same error message about expecting a function.

I’ve deleted the last step because something is wrong before that. Is it the syntax??

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ’ + crustType + ’ crust topped with ’ + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubtotal(orderCount) + getTax(orderCount);
}

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);


#4

Hi @seanalexanderharris, I overlook one particular part, see the comment again :wink:

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ' + crustType + ' crust topped with ' + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubtotal(orderCount) + getTax(orderCount); //<== getTax() should be empty and take no argument, delete the orderCount
}

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

The reason because you’ve defined getTax() function without taking in any parameter, so by calling getTax() without anything inside, it will automatically run the code block inside it, taking getSubTotal(orderCount) * 0.06 and return the value.

You should add back the last console.log, console.log(getTotal());, as it’s in the lesson’s instruction.

Tell me if it still throwing any error. :slight_smile:


#5

Again, I understand why that would be an error but it is still throwing up the same error about expecting a function.

This is on stage 3 of the lesson. I want to be sure I’ve got it right up to there first! ha. I feel like I’m bashing my head against a wall with this.


#6

@seanalexanderharris,

If you have made changes to the code like I mentioned, sometimes the browser needs to be refreshed for those codes to be registered.

Try see if that clears your situation (I think that will solve your problem). If not, may you post your last updated code here?

Cheers :slight_smile:


#7

Hey,

I refreshed but same result. Sorry for this being so fiddly! I appreciate your help :slight_smile:

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return-ii?action=lesson_resume

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ’ + crustType + ’ crust topped with ’ + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubtotal(orderCount) + getTax;
}

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);


#8

Hi @seanalexanderharris,

No worries. :slight_smile:

You forgot the brackets ( ) after getTax function.

Function calling should be getTax( ) :wink:

Hint: Check

function getTotal() {
return getSubtotal(orderCount) + getTax; //<== brackets ?
}


#9

Gosh. What a dummy I am. Changed that but still the error message (and I refreshed the page).

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return-ii?action=lesson_resume


#10

It’s okay. :slight_smile: @seanalexanderharris,

It is all right to go through every single code. Debugging is part of coding. Do provide your updated code here?


#11

Ok. Here’s all my code. I’ve read and checked it through so many times I’m seeing double…

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ’ + crustType + ’ crust topped with ’ + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubtotal(orderCount) + getTax();
}

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);


#12

Hi @seanalexanderharris,

I think I’ve figured out what’s the problem,

I’ve edited your code here, it is the same to what you’ve been posting for the last updated code, but because how this forum works, it changes your quotation marks ’ ’ into tick marks , there’s subtle differences.

Try copy the below code, and paste it into your exercise, it should work now

Edit: You have one ‘t’ that should be “T” in the getSubtotal(orderCount) + getTax();

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ' + crustType + ' crust topped with ' + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubTotal(orderCount) + getTax();
}

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

Delete your previous codes, refresh and paste. I’ve tested these codes, it is running fine.

Get back to me if there’s still anything. :slight_smile:


#13

Still the same error message. I tried copying and pasting the code three times - I refreshed the page too.

Could it be a bug??


#15

@seanalexanderharris,

It’s not a bug.

Edit: You have one ‘t’ that should be “T” in the getSubtotal(orderCount) + getTax();, should be getSubTotal(orderCount) + getTax();

The codes I’ve checked, it is running fine.

Maybe you should add the final console.log.

Final edited code below:

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log('Order: ' + crustType + ' crust topped with ' + topping);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubTotal(orderCount) + getTax();
}

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

console.log(getTotal());  //<=== getTotal() should be called for exercise 6 instruction 4

Note: My apology, final console.log should be without argument. Please refer to my edited post above. Something was over my head.

Sorry for not noticing it earlier, I was testing your code with my code (I wrote it differently versus yours), since we wrote it differently, it got mix up and produce the functioning code which I’ve tested.


#16

@seanalexanderharris,

Let me summarize what to be changed in your very first post (initial code) to ease your understanding. It was a bit jumbled up:

  1. Under function getTax(), getSubTotal() should take in orderCount as argument.

  2. Under function getTotal(), getSubtotal() should be changed to getSubTotal(),

  3. Under function getTotal(), getSubTotal() should take in orderCount as argument,

  4. Under function getTotal(), the getTax() should take no argument.

  5. Add console.log(getTotal()); for the final exercise’s instruction.

Hope it helps. :sweat_smile:


#17

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.