Use Libraries or Write My Own Code

When I am doing the challenges should I use libraries, or write my own code? How should I determine the cut off? In some cases it is clear (e.g. if it is about learning Bootstrap I obviously need to use Bootstrap), but in others it is not (e.g. when writing the calculator app should I use something like Math.js, or write the code on my own)?