Write the JavaScript to read the number of hours worked from the user. Then write the JavaScript to calculate how much money the user made if they were paid $12/hour for the first 40 hours worked, and $18/hr for all hours worked over 40. Then use console.log to print out the hours entered and the total amount made.
So that's the code I have to write.
I can get the first part no problem from 0-40. But I can't figure out how to have and if/else statement calculate the first 40 at $12/h and the remaining at $18/h.
my code right now looks like
let hours = Number(prompt("Numbers of hours worked"))
console.log("# of hours worked is " +hours)
let regularHours = (hours >=40
if (hours <= 40) {
console.log("In " +hours+ " you made $" +hours *12)
} else {
console.log("In " +hours+ "you made $" +)
can I define a variable to be like
let regularHours = hours <=40 *12
let overtimeHours = hours >40 *18
I tried that but it doesn't quite work.
Am I over complicating this?
Aucun commentaire:
Enregistrer un commentaire