These are chat archives for Codewars/codewars.com/kata-solving-help

14th
Nov 2017
kealan-parr
@kealan-parr
Nov 14 2017 21:34
Hi, is there a way to return a value from a function and do something else anyone? (EG)
return a( && hours = 0 ;)
Fernando Balandran
@kodaman2
Nov 14 2017 21:36
What do you mean something else mm
?
kealan-parr
@kealan-parr
Nov 14 2017 21:36
Can I then set a variable to 0 for example?
EG
return a ( THEN DO SOMETHING HERE  )
wollf92
@wollf92
Nov 14 2017 21:40
I mean, would
{
    DO SOMETHING HERE
    return a;
}
not be sufficient?
and why so?
what scenario are you thinking of
a return litterally places you back to a caller which continues its code until it's done, meaning there would literally be no time to execute the "THEN DO SOMETHING" from the original return
kealan-parr
@kealan-parr
Nov 14 2017 21:46
hI
Thanks for the answer
No it wouldnt work for my solution
Let me show you why
In my solution, if I set the hours as 0, then when I return it, I will have the wrong answer
So i need to return it (so its right) then set the hours as 0

```function timeConvert(num) {

var hours;

if (num < 0) { var hours = 0; return "00:00"; }

if (num > 60) {
hours = hours + 1;
return timeConvert(num - 60);

}

if (hours < 10 && num < 10) {
return "0" + hours + ":" + "0" + num;
}
if (hours < 10 ) {
return "0" + hours + ":" + num;
}
else {
return hours + ":" + num;
}
}
```

function timeConvert(num) { 

var hours;

if (num < 0)   { var hours = 0; return "00:00"; }

if (num > 60) { 
  hours = hours + 1; 
  return timeConvert(num - 60);

  }




if (hours < 10 && num < 10) {
return "0" + hours + ":" + "0" + num;
}
if (hours < 10 ) {
return "0" + hours + ":" + num;
}
else {
return hours + ":" + num;
}
}
wollf92
@wollf92
Nov 14 2017 21:56
I don't think its wise to tackle that kata that way
in the description itself, they point you towards a nice little hint called modulo
the point of the kata is to learn how to use that
Fernando Balandran
@kodaman2
Nov 14 2017 22:01
Yeah if you use the modulo your solution will be much cleaner, and probably less if/else statements.
wollf92
@wollf92
Nov 14 2017 22:13
lets say you have 200 minutes.
200 minutes has 3 hours (180 minutes) and 20 minutes rest
so the answer for the clock would then just be 3:20
200 / 60 = 3. (you'll have to fix JS double result)
200 % 60 = 20 (whatever is over when you have fit 60, 3 times in 200)
Fernando Balandran
@kodaman2
Nov 14 2017 22:26
sounds about right, find the hours, then find the minutes. One note, you can do Math.floor(200 / 60) to get 3. It is known as integer division or floor division.
wollf92
@wollf92
Nov 14 2017 22:26
Aww I wanted to keep that in as something he should find out :P
Fernando Balandran
@kodaman2
Nov 14 2017 22:28
dang it, well I just helped since his algorithm seem OK aside from that.
he still has to code it anyways :smile: