# Getting started with an assignment for a job interview - JS

Hey guys!

My first post here and I’m pretty sure it won’t be my last.

I am currently in the process of getting a job using JS and they’re very open with hiring a total beginner with some experience.

I have an assignment to prepare for - using JS - but I just don’t know how to start. The assignment seems easy enough, but because this is my first ever coding job, I don’t know where to start.

Is there anyone who can just guide me just so I know with what to begin.

Thanks so much!

Success!

Managed to write code for the assignment - just needed to trust what I’ve learned from here and go for it.

The assignment in question is a BMI calculator with set criteria that I have to submit it in.

I managed to do that and I’m interested in a code review if that’s possible.

Since this is a BMI calculator, would the proposed ‘‘let string’’ result in it working if you put more values - different heights and weights - in the calculator?

``````function calcBmi(weight, height) {

if(!isValid(weight, height)){
} else {
let heightInMeters = height/100;
let bmi = weight / Math.pow(heightInMeters, 2)
return Number(bmi.toFixed(2));
}
}

function isValid(weight, height) {
if(weight >= 1 && weight <= 300 && height >= 1 && height <= 250) {
return true;
} else {
return false;
}
}

let mediaWeight = 70
let mediaHeight = 190
let mediaBmi = calcBmi(mediaWeight, mediaHeight);

console.log(mediaBmi)
``````

It looks like your code performs the desired task. I would suggest indenting blocks of code for readability. I’d also suggest consistent use of `;`'s. Use them or don’t, but using them sometimes is inconsistent.

One last thing:

`bmi.toFixed(2)` is already a `Number`. There’s no need for the `Number` constructor.

Not exactly sure what you’re asking. I don’t know what the following refers to.

You can change the values that you assign `mediaWeight` and `mediaHeight` to, if that’s what you mean.

1 Like

Specific to how you call the calculator.
If you removed the let statements and just used:

`console.log(`Your BMI is \${calcBmi(70, 190)}`);`

It would be more compact and allow you to call the function with different weight/height combinations.

1 Like

I’m sorry

I just noticed that it was a bit awkward.

I’m asking if the code I submitted results in the BMI calculator working as desired - meaning that if you change the values (height, weight) on said calculator (not the code) - it will give you the BMI result.

Edit: so they’re not ‘‘hardcoded’’.

Thanks for the response!

1 Like
``````function calcBmi(weight, height) {

if(!isValid(weight, height)){
} else {
let heightInMeters = height/100;
let bmi = weight / Math.pow(heightInMeters, 2)
return Number(bmi.toFixed(2));
}
}

function isValid(weight, height) {
if(weight >= 1 && weight <= 300 && height >= 1 && height <= 250) {
return true;
} else {
return false;
}
}

``````

You mean like this?

I got a bit lost here.

When you post code, make sure you follow the guidelines here, How do I format code in my posts?
Otherwise, the forums markdown prevents your code from displaying properly.
@johnLohavichan296750’s code example is an example of not displaying properly. The back ticks used to create a template literal, and interpolate the return value of your function call into the string are missing. If you haven’t come across template literals yet, in your studies, I would stick with what you are familiar with, lest the prospective employer gets the impression that you know more than you do.

1 Like

I’ll check it, thanks for showing it to me.

I am aware of template literals, I was just fishing for some clarification.

So basically - for it to function as a rudimentary BMI calculator, does my code suffice or do I have to do as specified?

Ah good point @midlindner - edited my post with the code back tics.

2 Likes

Not sure what was specified, but as long as the formula is correct, your code does the job. The function produces consistent results.

1 Like

I apologize if I wasn’t clear.

Using this - console.log(`Your BMI is \${calcBmi(70, 190)}`);

The code I submitted produces the BMI number in the console. That’s true.

However, if someone punches in different values (in the calculator) - would that produce a different BMI number? If a random person goes on the website and puts in his height and weight would it show the BMI number that’s calculated for that specific height and weight or will it always show the 70/190 result or none at all?

In order to calculate the bmi for a weight other than 70 and a height other than 190, the numbers would have to be ‘hardcoded’ as you’ve mentioned. If the specifications were for having variables assigned to the weight and height, I’d stick to that. If it wasn’t specified, using the actual values in your function call is fine. You could combine the approaches, so to speak:

``````let weight = 70;
let height = 190;
``````

To check another weight/height combination, you change the values. In order to allow users to enter a weight and height without changing the code, you’d need an interface of some sort. Either a webpage or a console application. That seems beyond the scope of what you are doing.

1 Like

Perfect

Thank you soooo much!

Last thing - and this is probably going to be silly:

I need to do a pull request on GitHub and I’d like to know how to actually do that. I checked online but I’m unsure - I have to first put the code as a separate repository and then do a pull request?

I’m supposed to do a pull request and add this one guy as a reviewer.

I’m no github guru. Here’s a link that may help, Creating a pull request - GitHub Docs

The assignment in question is a BMI calculator with set criteria that I have to submit it in.

I managed to do that and I’m interested in a code review if that’s possible.

Since this is a BMI calculator, would the proposed ‘‘let string’’ result in it working if you put more values - different heights and weights - in the calculator?
Love❤️ From Battlegrounds Pngs - https://www.battlegroundspng.com