Below is some code that has been deliberately broken so that you can fix it.
It’s supposed to ask you to to a bit of job research. It will ask you to enter the name of a job and the yearly salary you could earn if you get that job.
It should then calculate how much that yearly salary would mean you earn each month, year and day (before tax is taken off)
There’s one syntax error which prevents it from running and two logic errors where the code does what it’s told to do but doesn’t calculate the correct result.
- Fix the syntax error on line 8
Syntax errors prevent the code from running because you’ve broken the rules of the programming language.
Hint: look at the brackets.
- The weekly salary is correct but is rounded to 4 decimal places instead of 2. Fix the logic error.
This challenge assumes that there are 52 weeks in the year which isn’t really true, but it’s close enough.
The salary should be rounded to 2 decimal places so you can see pounds and pence.
Hint: Look at lines 10-12
- The daily salary is incorrect. Find and fix the logic error
The code has got confused about how many days there are in a year. We’re ignoring leap years here, so you need to change it so that the yearly salary is divided by 365.
On the next page you’ll get some ideas for projects where you can try to avoid making logic errors