[Solved] Some prompt() comment exercises [closed]


This should do the trick:

(function(show, askFor){
  var first = +askFor("The first number:"),
    +second = askFor("The second number:");
  show([
    "You entered:", first, "and", second, 
    "Sum:", first+second
  ].join(" "));
})(alert, prompt);

(function(show, askFor){
  var first = +askFor("The first number:"),
    second = +askFor("The second number:");
  show([
    "You entered:", first, "and", second,
    "Sum:", first + second,
    "Difference:", first - second,
    "Product:", first * second,
    "Quotient:", first / second,
    "Modulus:", first % second
  ].join(" "));
})(alert, prompt);

(function(show, askFor){
  var first = +askFor("The first number:"),
    second = +askFor("The second number:"),
    third = +askFor("The third number:");
  show("The average of those numbers: "+ (first+second+third)/3);
})(alert, prompt);

(function(show, askFor){
  var hours = +askFor("How much you worked this week:"),
    rate = +askFor("And what's your hourly rate:"),
    overtimeRate = rate*1.5,
    regularHours = Math.min(40, hours),
    overtimeHours = Math.max(0, hours-40),
    regularPay = rate*regularHours,
    overtimePay = overtimeRate*overtimeHours;
  show([
    "Total Hours Worked:", hours,
    " Regular Pay:", regularHours, 
    " hours @ $", rate, "/hour", 
    " = $", regularPay, 
    " Overtime Pay:", overtimeHours,
    " hours @ $", overtimeRate, "/hour",
    " = $", overtimePay, 
    " Total Pay: $", regularPay+overtimePay  
  ].join(""));
})(alert, prompt);

5

solved Some prompt() comment exercises [closed]