1

Javascript beginner here, I keep getting a wrong answer to this question:

"First, figure out if we have enough slices now. Use a comparison operator to figure out if there are enough. Assign the result to the enoughSlicesNow variable."

//Variables are below//

var cakes = 5;
var slicesPerCake = 6;
var attendees = 60;
var bakers = 3;
var cakeBakingTime = 1;
var hoursLeftUntilParty = 5;

This is what I tried but it will not accept:

(cakes * slicesPerCake)>= attendees 

var enoughSlicesNow = false 
1
  • "Assign the result to the enoughSlicesNow variable" you are always assigning false to enoughSlicesNow, not the result of the comparison. Commented Jan 19, 2017 at 5:06

3 Answers 3

1

Looks like you need:

var enoughSlicesNow = (cakes * slicesPerCake) >= attendees;
Sign up to request clarification or add additional context in comments.

Comments

0

You can do like this using ternary operator

var cakes = 5;
var slicesPerCake = 6;
var attendees = 60;
var bakers = 3;
var cakeBakingTime = 1;
var hoursLeftUntilParty = 5;


 var enoughSlicesNow = (cakes * slicesPerCake) >= attendees ?true:false
alert(enoughSlicesNow)

DEMO

Comments

0

Do you want like this...

    var cakes = 5;
    var slicesPerCake = 6;
    var attendees = 60;
    var bakers = 3;
    var cakeBakingTime = 1;
    var hoursLeftUntilParty = 5;
    
    
     var enoughSlicesNow = (cakes * slicesPerCake)>= attendees;
     if(enoughSlicesNow ==true){
         alert('Enough');
       }
    else
    {
      alert('Not enough');
    }

2 Comments

if(true == x) should always be rewritten to if(x), unless you are like using === and you know what you are doing
it is also possible to compare with true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.