Motivating students is super important. Especially when the studying gets difficult and challenging.
Read this great article about different kinds of motivation and strategies for motivating students
Here are some more practical ways of motivating students in class
Use authentic tasks: something that learners believe they would actually do in real life (e.g. making a menu open when a button is clicked). Or the flip-side of this, avoid using examples like var foo = "bar";
Draw on your experience to show how the things you are teaching are relevant in your day-to-day job. Remember that students often have no idea what a programmer does daily
Share your imposter syndrome (the belief that a person's achievements are lucky flukes and a fear that "someone will finally figure this out"). We encourage you to share stories of when you made mistakes so that students know that it is OK to find programming hard
Give context for everything. What is the reason we are talking about promises fx
Make the students compare themselves to where they were 3 weeks ago