# Functions - Rock, Paper, Scissors

I’m half way through, but i don’t know how to correctly use one function inside other. In my function comparison Im trying compare my MovetypeFirstPlayer and MovetypeSecondPlayer to their returns. And i’m getting undefined result

``````// All code should be written in this file.

let MoveTpA = 'Rock';

let MoveTpB = 'Paper';

let MoveTpC = 'Scissors';

let indexFirst = Math.floor(Math.random() * 3);

let indexSecond = Math.floor(Math.random() * 3);

function MovetypeFirstPlayer () {

if (indexFirst === 1) {

return MoveTpA;

} else if (indexFirst === 2) {

return MoveTpB;

} else {

return MoveTpC;

}}

function MovetypeSecondPlayer () {

if (indexSecond === 1) {

return MoveTpA;

} else if (indexSecond === 2) {

return MoveTpB;

} else {

return MoveTpC;

}}

let pointsFirst = 0;

let pointsSecond = 0;

function comparison () {

if (MovetypeFirstPlayer() === MoveTpA && MovetypeSecondPlayer () === MoveTpB) {

pointsFirst = pointsFirst + 0;

pointsSecond = pointsSecond + 60;

} else if (MovetypeFirstPlayer() === MoveTpA && MovetypeSecondPlayer () === MoveTpC) {

pointsFirst = pointsFirst + 90;

pointsSecond = pointsSecond + 0;

} else if (MovetypeFirstPlayer() === MoveTpB && MovetypeSecondPlayer () === MoveTpA) {

pointsFirst = pointsFirst + 60;

pointsSecond = pointsSecond + 0;

} else if (MovetypeFirstPlayer() === MoveTpB && MovetypeSecondPlayer () === MoveTpC) {

pointsFirst = pointsFirst + 0;

pointsSecond = pointsSecond + 9;

} else if (MovetypeFirstPlayer() === MoveTpC && MovetypeSecondPlayer () === MoveTpA) {

pointsFirst = pointsFirst + 0;

pointsSecond = pointsSecond + 90;

} else if (MovetypeFirstPlayer() === MoveTpC && MovetypeSecondPlayer () === MoveTpB) {

pointsFirst = pointsFirst + 9;

pointsSecond = pointsSecond + 0;

} else {

pointsFirst = pointsFirst + 0;

pointsSecond = pointsSecond + 0;

return pointsFirst, pointsSecond;

}

}

console.log(MovetypeFirstPlayer());

console.log(MovetypeSecondPlayer());

console.log(comparison());
``````

Hello, @object7318787423, and welcome to the forums!

Consider these very simple functions:

``````function explicitReturn() {
return "Hello!"
}

function noExplicitReturn() {
//I literally do nothing, but I still return something..
}

console.log(explicitReturn())

console.log(noExplicitReturn())
``````

Output:

Hello!
undefined

You might also consider only calling your `MovetypeFirstPlayer()` and `MovetypeSecondPlayer()` once inside your `comparison()` function, and assign the return values to variables rather than calling the functions in each of your `if..else if` conditions.

Also, your code is difficult to read since the forums markdown has mutilated your original formatting. Following these guidelines, you can preserve your code’s original formatting making it much easier for others to help you. I have edited your post using said guidelines, so you can see the difference.