Frankie and Johnny game. What should Johnny strategy if he wants to minimize his expected loss? Frankie and Johnny play the following game.
Frankie selects a number at random from the interval
$[a, b]$. Johnny, not knowing Frankie’s number, is to pick
a second number from that same inverval and pay Frankie
an amount, W, equal to the squared difference between
the two
[so $0 ≤ W ≤ (b − a)^2]$. What should be Johnny’s
strategy if he wants to minimize his expected loss?
Attempt: Let $Y$ be Frankie's choice. 
Then Johnny wants to choose $k$ so that $E(Y - k)^2$ is minimize. 
Can someone please help me? I am having trouble. The answer is Johnny should pick $(a+b)/2$ to minimize his loss.
 A: Unless you know something about Frankie's bias in picking numbers, you have to assume a discrete uniform  distribution, which has a probability mass function of $p_Y(h)=1/(b-a+1)$ on the support $h\in\{a..b\}$.
So the expectation is:
$$\begin{align}
\mathsf E[(Y-k)^2] & = \sum_{h=a}^b (h-k)^2/(b-a+1) & : &  h\in\{a..b\}, k\in\{a..b\}
\end{align}$$
As you noted in the comments, the minima $k$ is the value that sets the differential to zero. (Rather, your answer will be the nearest integer value.)
$$\begin{align}
0 & = \frac{\mathrm d\;}{\mathrm d k}\mathsf E[(Y-k)^2]
\\ & = \frac{\mathrm d\;}{\mathrm d k}\sum_{h=a}^b (h-k)^2/(b-a+1) & : &  k\in\{a..b\}
\end{align}$$

Note  This is assuming Frankie is only allowed to pick integers.  Though you get the same result for a continuous uniform distribution, $f_Y(y)=1/(b-a)$.
$$\begin{align}
0 & = \frac{\mathrm d\;}{\mathrm d x}\mathsf E[(Y-x)^2]
\\ & = \frac{\mathrm d\;}{\mathrm d x}\int_{a}^b (y-x)^2/(b-a) \operatorname d y & : &  x\in[a..b]
\end{align}$$
A: The simplest approach is to just expand the expectation and minimize. So $$E[(Y-k)^2]=E[Y^2]-E[2kY]+E[k^2].$$ Assuming the second moment of $Y$ is finite, we take the derivative with respect to $k$ and set equal to zero. $$-2E[Y]+2k=0,$$ or $$k = E[Y].$$
Note that we have yet to use any distribution. This holds for all distributions with finite second moment. Now for a continuous uniform random variable on $[a,b]$ the mean is $$\mu = {{a+b} \over {2}} $$ so that is the optimal value of $k.$ The second derivative confirms this provides the minimum. 
