How do I write the function to quarter in lesson 8


#1


// Define quarter here.





if (quarter() % 3 === 0 ) {
  console.log("The statement is true");
} else {
  console.log("The statement is false");
}


#2
  1. Define a function called quarter which has a parameter called number.
  2. This function returns a value equal to one quarter of the parameter. (i.e. number / 4;)

var quarter //your variable

= function(number) //your functio and its parameter

return number/4 //your return statement that was given to you

So basically it should look something like this:

var quarter = function(number) { //you need { and } as well!
return number/4
}

#3

I don't know how to do lesson 8, function, returns and if/else...Can somebody write me whole exam? Thank you


#4

@bibleman13 this is my new code but it comes out as false and to pass it needs to be true

var quarter = function (number) {
return number/4
}

if (quarter() % 3 === 0) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}

please help :confused:


#5

Yeah I had the same exact problem when I was going through this lesson a couple of months ago! It was tricky but basically in your if statement specifically your quarter statement you need a number that when divisible by 3 gives you no remainder. So for example 72 divided by 3 gives you 24 with no remainder. That should be the only problem you have everything else looks correct.

And when I say if statement with quarter function I do mean here: if (quarter() % 3 === 0) {
Specifically, ter() % in the parentheses :smiley:


#6

I believe this should lead you through everything you need to know for this lesson @sakalic


#7

Thanks for the help @bibleman13

:smile:


#8

No problem! Happy to help! Happy coding! :smiley:


#9

yeah, thank you @bibleman13


#10

No problem! Hope the other lessons are less confusing for you! :smiley:


#11

now I'm just speeding through the functions


#12

Well thats great! Sometimes, and I find this with many things, you struggle on something for a while and then once you get it its like a light bulb comes on and poof you breeze through it all and you wonder how you ever got stuck in the first place haha


#13

so this lesson confuses me :slight_smile: (12.Function & if / else) I think I did it right but there's some mistake???


#14

Ah. It would seem you are missing an ! right after eye in your return Get some more shut eye. So basically this

return "Get some more shut eye";

needs to be this

return "Get some more shut eye!";

#15

oh, what a stupid mistake ! :slight_smile: thank you


#16

No problem! And believe me its too easy to miss a punctuation xD I have done that wayyy to many times haha


#17

I have too. and most of those times it came out to me not figuring out the problem for like a week
lol
:joy:
@bibleman13 @sakalic


#18

I can help you in understanding with a different example. Please refer the example created by me.

var qualification = function(number){
var present = prompt("What is the present year?");
return present - number;
};
var dob = prompt("Enter your birth year");

if (qualification(dob) >= 18 ) {
console.log("Wow!! You are a Major");
} else {
console.log("Oops.. You are still a Minor");
}

Hope this will help you understand previous lessons also little better.
In this i am asking user to enter his Date of Birth's year first.
Then i am asking the user to enter the current year.
So after calculations if user is <18 years old it will say he is a Minor, else if he is >=18 years it will say he is Major.


#19

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