What is a code defense session of an interview like?

What is a code defense session of an interview like?
0

#1

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?

Thanks.


#2
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).


#3

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


#4

Did you write this code or was it already given to you to figure out what (if anything is wrong with it)?

The line:

msg.innerHTML = "";

is in both the if and else blocks of code. It is redundant. If the msg should be a blank string whether or not number.length is not equal to 3, then you should only write it once either below or after the if/else statement.

Either

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

OR

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

Also, I would suggest using a ternary operator here to set the opacity to reduce repeat code. Also, it is not necessary to set the opacity to string values. Numeric values will work just fine.

button.style.opacity = number.length !== 3  ? "0.5" : "1";
msg.innerHTML = "";

#5

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 …


#6

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

Very valuable input. Thanks


#7

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.


#8

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