This is a very good first start!
Firstly, you seem to have accidentally put some of the code outside of the function – when it has return
statements and the like. That bit of code is below:
if(count>0){
return count,"Bet";
}
else if(count<=0){
return count,"Hold";
}
You need to move it to the correct position, or else your code will throw an error and won’t run. That’s because the return
statement errors when it’s not inside a function, because it doesn’t know what to do exactly.
In addition, in JavaScript, the comma (,
) operator will evaluate each of its statements and then return the last in the sequence (technically, it only takes two arguments and binds left-to-right, but that isn’t important).
function example() {
return 1, 2, 3, 4 // returns 4
}
Likewise, the statement
return count,"Hold";
is identical to
return "Hold";
And that definitely won’t pass any of the tests. Instead, to join two strings together, we can use the concatenation operator (+
). If we pass it a number and a string, it will coerce the number into a string and then join them together. So, 1 + "Bet"
will be 1Bet
.
But what you want, I suspect, is 1 Bet
(with a space between the two). You can include spaces in JavaScript strings, so you just need to change "Bet"
to have a space at the start. Note that ( "Bet")
(i.e., placing the spaces before the "
, won’t work, because it’s not part of the string, but part of the code).
Once those issues are fixed, it might be a little easier to solve your problem. Good luck!
EDIT: I made the changes I just described above, and managed to get it to work. To summarise, those changes were:
- Move the stray bit of code back into the function
- Change the
,
operator to instead concatenation (+
) operators
- Make sure there is a space between the number and the “Bet” or “Hold” text