Well, that is an interesting question
First of all, we need to re-arrange these values and put them in order
40,7,2,35,12,23,18,28
ordered: 2,7,12,18,23,28,35,40
minimum value is the least value = 2
maximum value is the highest record = 40
The median is the middle score for a set of data that has been arranged in order (if the number of values is odd). For the case of even values number, you simply have to take the middle two scores and average the result
median =

The first quartile is the median of the left-side group of records {2,7,12} after assigning the median (20.5)

The third quartile is the median of the right-side group of records {28,35,40} after assigning the median (20.5)

And we are done now.
Ask me if there is any difficulty faces you!