Why was Jesus tempted by the devil?
Here's the answer:
Satan wanted to make Jesus sin, but Jesus didn't sin.
Satan knew that if he could make Jesus do something wrong and sin, then Jesus couldn't be our Savior. In order to pay the price for our sins and take our place by dying for our sins, Jesus Himself could never sin. Satan tempted Jesus, or tried to make Him do things He was not supposed to do. Even though Satan offered Jesus many wonderful things, Jesus chose to not sin and resisted Satan's temptation.
Jesus was an example to us. We can say no to temptation too.
"We have a high priest [Jesus] who can feel it when we are weak and hurting. We have a high priest who has been tempted in every way, just as we are. But he did not sin. So let us boldly approach the throne of grace. Then we will receive mercy. We will find grace to help us when we need it" (Hebrews 4:1–16).