Honestly, it's pretty clean code, that's not the problem here. Problem is the code is not extendable or easy to reuse, also it's easy to miss the default state.
I had a colleague who quit in his 4th semester after it became obvious, that he finished only courses, where he could cheat his way through (e.g. exercise courses, where he copied other people's work).
Third semester CS makes me think, that the concept for "format strings" should have appeared at some point.
That said, what kind of curriculum? The wording as "classmate" makes me wonder.
Edit. I somehow misread this as being Python for some reason. In JavaScript, the solution is apparently less obvious? Though number.toString().padStart(2, '0') isn't bad either.
184
u/lecrof46 Jan 16 '23
btw, you could just write
String(num2).padStart(2, "0")2
u/StrangePractice Jan 16 '23
What color theme?
58
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 16 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
42
u/[deleted] Jan 16 '23
or
should be the easiest and fastest way. The use of any string function is just wasted computation time.
6
u/[deleted] Jan 16 '23
Id just do
3
u/NUTTA_BUSTAH Jan 17 '23
Mmmm salient Javascript
3
u/5zalot Jan 17 '23
This was probably a school assignment with a line count minimum requirement. Lol.
2
u/jimmpony Jan 16 '23
sometimes copilot will spit something like this out and I just let it happen
2
u/foxer_arnt_trees Jan 17 '23
Honestly, it's pretty clean code, that's not the problem here. Problem is the code is not extendable or easy to reuse, also it's easy to miss the default state.
1
u/willyrs Jan 17 '23
At least he didn't import leftPad
1
u/TurncoatTony Jan 17 '23
break should be two spaces back. :D
1
u/bogdan5844 Jan 17 '23
Why
num2tho ?0
u/MDTv_Teka Jan 16 '23
All I can think when I see string interpolation in js is the banana incident
0
u/[deleted] Jan 16 '23
[deleted] — view deleted comment