This story is found in 1 Samuel 1
let's start from the beginning.
A war has broken out between the Philistines and the Israelites. Saul, with the Israelites, is the "commander" for them. A giant named Goliath, from the Philistines, came and started taunting them. All the Israelites including Saul were terrified.
Flash sideways to Jesse, the father of David and three of the men at the camp. He sent David to bring his brothers some bread and cheese and ask how they are. When he gets there he over hears Goliath smack-talking them and God. This angers David and he wants to fight him saying; "When a lion or a bear came and carried off a sheep from the flock, I went after it, struck it and rescued the sheep from its mouth. When it turned on me, I seized it by its hair, struck it and killed it."