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 Multiplication(a, b) {
    return a * b;
  }
  Multiplication(125,5)
  Input In [15]
    let x = myFunction(4, 3);   // Function is called, return value will end up in x
        ^
SyntaxError: invalid syntax

Temperature

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

function Celcius(Fahrenheit) {
    return (5/9) * (Fahrenheit-32);
  }

Celsius(0)
  Input In [12]
    function Celcius(Fahrenheit) {
             ^
SyntaxError: invalid syntax

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)
  Input In [13]
    function IsOdd(x){
             ^
SyntaxError: invalid syntax

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)
  Input In [14]
    function DaysHoursMinutesSeconds(x){
             ^
SyntaxError: invalid syntax