JavaScript Code

The codes below all use the JavaScript language in order to perform something.

Function

This code defines a function and takes 2 numbers as a parameter and returns the product of the 2 numbers.

function myFunction(a, b) {
  return a * b;
}
myFunction(125,5)
625

Temperature

The code below takes an integer input that we assume is the degrees in Fahrenheit and then determines the code in Celsius.

function toCelsius(fahrenheit) {
    return (5/9) * (fahrenheit-32);
  }

toCelsius(0)
32.22222222222222

Even/Odd Number

This code contains a function that takes one number as the parameter. Then, it determines if the number is even or odd based on the remainer when divided by 2.

function IsOdd(x){
if (x % 2 == 0) {
    console.log(x + " is an even number");
}  else {
   console.log(x + " is an odd number");
}

}
IsOdd(24)
24 is an even number

Time

This code contains a function that takes one number as the parameter and we assume it to be the number of hours. Then, the code determines many days, minutes, and seconds those hours are equivalent to.

function DaysHoursMinutesSeconds(x){
    console.log(x + " hour(s) is equivalent to " + x/24 + " days, " + x*60 + " minutes, and " + x*3600 + " seconds.")
}
DaysHoursMinutesSeconds(48)
48 hour(s) is equivalent to 2 days, 2880 minutes, and 172800 seconds.