What is a code defense session of an interview like?

Hello guys,

I have an interview tomorrow and it involves 10 minutes of code defense session. We were told told to code this https://codepen.io/samuelachema/pen/zJOgad which is an ARMSTRONG test of 3 digits number as part of the code challenge.

Does anyone have an idea on how the code defense session works? If you can, take a very good look at the code, what will you say needs to be improved?


if(number.length !== 3){
		msg.innerHTML = "";
        button.style.opacity = "0.5";
    } else {
		msg.innerHTML = "";
        button.style.opacity = "1";

I wonder why they have msg.innerHTML = “” in both parts of the if statement? That suggests the line should not be there.

I would guess the ‘defense’ is going to require you to understand exactly what each line of code does and why it is written in that way (versus another way).

Thanks for your time @hbar1st . msg.innerHTML = “”; is to clear the message div any time there is an input length test.

I just googled an “armstrong number”. Definition: “A number a is an Armstrong Number or narcissistic number if it is equal to the sum of its own digits raised to the power of the number of digits. This definition is dependent on the base, b, used to represent the number.” If you enter number 238, formulae for calculating would be (2^3)+(3^3)+(8^3). So if this sum is equal to number itself, then it is armstrong number. I guess you should also explain how your i/o works and why is styled that way. Answer for me would be that is easier for user to understand what is asked from him/her. If it is, then say it is, if it’s not then say it is not armstrong number. Edit: Traditionally is done with three numbers. Why it’s not generally applied by more then three numbers, i don’t know. It shouldn’t be to computationally intensive … Ps: there’s not two digit armstrong number or say post on interwebz’s forums … I’m to lazy to calculate on paper …

Also, I would suggest using a ternary operator here to set the opacity to reduce repeat code.

Very valuable input. Thanks

I have never had an interview that included something that I heard called a “code defense”. My guess is that they will have you go through your solution for them. They might ask why you chose to do things a certain way, why you didn’t choose to do something else, how efficient your solution is, how robust your solution is, etc. Despite the name, try hard not to get too defensive. If you see a weakness in your code, admit to it. That’s a normal thing to have happen and part of why code reviews exist for developers.
My guess is that the rationale for this is to confirm that you wrote your own code and understand it (no StackOverflow copy-pasta), to see your thought process and the way you approach problems, and generally to get a sense of what it would be like to talk to you about your code. Remember that when a developer is interviewing you, what they are trying to figure out is “Do I want to work with this person?”. You don’t need all the answers or to write perfect code, but you need to be smart, know enough that they don’t feel like they have to hold your hand, and be someone they want to collaborate with.

I wish I saw this earlier, not that I was that defensive in a bad way. I just got done with the interview. Hoping for the best. Thanks all

Hi @Devspert . I hope you got the job?

I didn’t get this one in particular but I’m happily engaged now.

1 Like