In most Algebra courses, in the chapter on Variation, there is explanatory narrative that is well worth reading.
And various kinds of variation problems are illustrated by carefully stated Examples, worked out in full. Reading them is one way to learn this material. And one also presumes that the teacher gives you some instruction along those lines, so it is quite useful to listen and, when you need to ask a question, to do so.
y = kx
3 = k(12)
therefore k = ¼
Now you know the whole formula and can find y when x=18.