/    Sign up×
Community /Pin to ProfileBookmark

New to java and i need help

Hello guys i am very new to java and i am doing a course atm. ill cut to the chase. this is my code so far:

[CODE]let getSleepHours = (day)=>{
switch(day)
case: “monday”
return “7”;
break;

case: “Tuesday”
return “6”;
break;

case: “Wednesday”
return “9”;
break;

case: “thursday”
return “8”;
break;

case: “friday”
return “5”;
break;

case: “saturday”
return “12”;
break;

case: “sunday”
return “14”;
break;
};

let getActualSleepHours = ()=>{

};
[/CODE]

And this is where i am stuck : inside the getActualSleepHours() function, call the getSleepHours() function for each day of the week. Add them all together and return the result using the arrow function syntax and implicit return.

I tried to fugure out how to loop through the switch with a for loop but i cant really figure out how to do this with different strings (monday,thuesday etc.)

cant wait for help thank you so much in advance

~oli

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@itengineerDec 10.2017 — First you have errors in the syntax: wrong location of colons and missing curly brackets. It is good practice to have consistent names format - capitalise all days. Also would be better in this case to return proper numbers than strings.

If I good understand your issue, a solution could be:
<i>
</i>let getActualSleepHours = ()=&gt;{
var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var sum = 0;
for (let day of days) {
sum = sum + parseInt(getSleepHours(day));
}
return sum;
};
var hours = getActualSleepHours();
console.log(hours);


** Please use forum bb code tags when posting code **
Copy linkTweet thisAlerts:
@rootDec 10.2017 — You are new to java? this is JavaScript forum, nothing to do with Java, Javas Forum is [COLOR="#800000"]here[/COLOR]
Copy linkTweet thisAlerts:
@itengineerDec 10.2017 — His question is on JavaScript, it is clear from the code.

BTW . - I would edit my post myself, unfortunately did not find such a option. Why is not this possible?
Copy linkTweet thisAlerts:
@rootDec 10.2017 — His question is on JavaScript, it is clear from the code.

BTW . - I would edit my post myself, unfortunately did not find such a option. Why is not this possible?[/QUOTE]


I have never seen JavaScript written like that before. Not even my browser like that code, justs issues errors all over the place.

You will also be surprised at how much Java Code looks like JavaScript and how many people post Java quesrion in the JavaScript forum, hence the title on the JavaScript forum [B]JavaScript (not Java) [/B] and still people post Java In here.
×

Success!

Help @itsolidude spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...