# Declaring Functions

#1

// Write your foodDemand function below.
// Last hint: In your reusable block of code, end each line
// with a semicolon (
var functionName = function foodDemand (âfoodâ); {
console.log(âI want to eatâ + âfoodDemandâ);}

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

```

Replace this line with your code.

``<do not remove the three backticks above>``

#2

Hi your function should look like that

``````
var foodDemand  = function() {
}
``````

You shouldnât put the `" "` around the argument `food`.

#3

thanks can you help with this one?
You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

You want to declare a function that calculates the cost of buying 5 oranges.
You then want to calculate the cost of the 5 all together.
Write a function that does this called orangeCost().
It should take a parameter that is the cost of an orange, and multiply it by 5.
It should log the result of the multiplication to the console.
Call the function where oranges each cost 5 dollars.

this is what i have:
var function orangeCost(cost * 5);
{console.log(orangeCost);}

orangeCost(â5â)

#4

First your function should look like that and should have as argument `price` Without `" "`

``````
var orangeCost = function(price) {

}
``````

Inside the function you should do the math

``````return  price  * 5

``````

So that when you call the function with the number 5 Without the `" "` around it.

#5

how do i define price

#6

Just by calling the function orangeCost() like that

``````orangeCost(5)

``````

#7

var quarter function {return number/4;}

if (quarter(9) % 3 === 0 ) {
console.log(âThe statement is trueâ);
} else {
console.log(âThe statement is falseâ);
}

Im not sure if i am defining the function correctly. Its supposed to go in parenthesis?

#8

HI you function quater should be like that

``````var quater = function(number) {
#here goes the return statement
}

``````

and should that as argument `number`

#9

Iâm still getting a syntax error??

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

if (quarter(9) % 3 === 0 ) {
console.log(âThe statement is trueâ);
} else {
console.log(âThe statement is falseâ);
}

#10

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

if (quarter(12) % 3 === 0 ) {
console.log(âThe statement is trueâ);
} else {
console.log(âThe statement is falseâ);
}

I fixed it to this but its unexpected token function

#11

nvm was missing my = sign

#12

var sleepCheck = function(numHours)
{
if (numhours > 8){
return (âYouâre getting plenty of sleep! Maybe even too much!â);};
else {
return (âGet some more shut eye!â);
};
}

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

do you have any idea whats wrong with this?

#13

var sleepCheck = function(numHours)
{
if (numHours >= 8)
{return âYouâre getting plenty of sleep! Maybe even too much!â;}
else {
return âGet some more shut eye!â;
}
}

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

so i have this but its saying Oops, try again. It looks like sleepCheck() isnât returning âYouâre getting plenty of sleep! Maybe even too much!â when numHours is 10. Check your if / else syntax and whether youâre using the correct comparison operator.

#14

Hi first you should remove the ; after your closing if ans else statement

``````
var sleepCheck = function(numHours) {
if (numHours >= 8) {
return ("You're getting plenty of sleep! Maybe even too much!");
};<= this one
else {
return ("Get some more shut eye!");
}; <== this one too
}

``````

then here

``````
if (numhours > 8)
``````

you change `numhours` to `numHours` and put >= instead of just >

#15

I just ran it work, try to refresh the page

#16

weird still not working for me but thanks glad i know its correct before moving on

#17

var userChoice = prompt(âDo you choose rock, paper or scissors?â);
var computerChoice = Math.random();
console.log(computerChoice)
if (computerChoice //between 0 and .33// ) {computerChoice = ârockâ;}
if else (computerChoice //between .34 and .66// {computerChoice = âpaperâ;}
else {computerChoice = âscissorsâ;}

So I am wondering how to write a condition that says computerChoice is between 0 and .33 but not sure how to do that?

#18

do it like that

``````if (computerChoice <= 0.33)
``````
``````else if (computerChoice <= 0.34 && computerChoice <= 0.66)

``````

#19

A more easier way to write the conditions is to focus on the two easiest ones. Such as the first and last one. So you would write something like this:

if(computerChoice < 0.34) <---- This basically means any number until 0.34 not including 0.34
{
}
else if(computerChoice > 0.66) <----- This basically says anything over 0.66 but not including 0.66
{
}
else
{
}

So you do not have to think about the middle between 0.34 and 0.66