Most people probably have been in the same position as you are now at some point, and you really shouldn’t feel discouraged about it because it’s just part of the learning process, and not least because you seem to have just started. My approach to it is:
- Read any documentation carefully and attempt a challenge only with what I know and what I have been taught first
- Don’t get distracted by writing short, fancy-looking code—aim to finish the challenge with logically-clear, well-formatted and well-commented code first and consolidate what you know/have just learnt
- Refactor your code where possible and submit your answer
- Study other people’s solution and learn from them by reading documentation and asking questions
- Don’t hesitate to get ask others to review your code (provided that your code is readable) and see what you can do to improve
I think writing short code is fun sometimes if you treat that as a brain-stretching exercise (like on codewars.com), but the goal shouldn’t always be short, as short doesn’t necessarily mean clean, maintainable, and/or more performant.