Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
McLarenCollege / averageOfNumbers.md
Last active January 18, 2022 05:51
Exercise Name : Average Of Three Numbers

Here is an example of a function

function square(num){
   let squareOfNum = num * num;
   return squareOfNum;
}
let result = square(5);
console.log("The square is " + result);

Write a function named averageOf3 that takes three numbers as parameters and returns the average of the three numbers.

@McLarenCollege
McLarenCollege / ticketPriceUsingIfElsePart2.md
Last active December 21, 2021 11:09
Exercise Name : Ticket Price Using If-else part2

//NOTE: Dont use if-else-if. You can use only if-else

Given two variables age and day, write code to determine the ticket price as per the following rules :

  • For a child (age less than 12) the ticket price is always 50.

  • For a senior citizen(age greater than or equal to 65):

    i) if it is weekend (Saturday/Sunday) the price is 70.
    

ii)if it is a weekday the price is 80.

@McLarenCollege
McLarenCollege / cinemaHallIfElse.md
Last active December 21, 2021 11:06
Exercise Name : Cinema Hall If-Else

A cinema is showing movie to childeren (age < 18) for free and charging adults (age >= 18) with $10 per ticket.

Write if-else statements to print the following messages according to the given age.

For adults print the following messages to the console:

Please pay $10.
Please proceed to the cinema hall.

For children print the following message to the console:

@McLarenCollege
McLarenCollege / partyTime.md
Last active December 21, 2021 11:00
Party Time

Given the details of Anu's birthday write a boolean expression to check if its Party Time (Anu's birthday) by comparing it with the details for the given day.

Note: You can assume that the given year will always be greater than Anu's Birth Year.

CODE TEMPLATE


let anuBirthDay = 26;
let anuBirthMonth = "August";
let anuBirthYear = 1986;

Write down your function tracing

function rossy(state) {
    return (state === 4);
}

function maxwell(a, b) {
    return rossy(a) || (a > b);
}
@McLarenCollege
McLarenCollege / FunctionTraceFooBar.js
Last active October 12, 2021 03:41
Exercise Name : Function Trace Foo Bar
//FUNCTION TRACE 3
// Requirements: Create a trace output file showing each function call
// including parameter values, and each return value. You should be able
// to step through with pen and paper - do not run the code on your computer
// Tip: To refresh your memory of how to write trace output, see this gist:
// https://gist.github.com/McLarenCollege/e276ecc7dc3485a483be469f61dfd671
function foo(koo, y) {
if ((koo % 3) !== 0) {

Write a function called findGreatest that accepts three numbers as arguments and returns the greatest of the three numbers using if-else statemets

let num1 = 5;
let num2 = 6;
let num3 = 7;

// Write your function here

Write a function names getExamResult that accepts the students marks of three subjects as arguments and returns the strings "pass" or "fail" depending on whether he has passed or failed .For passing the average score should be greater than or equal to 40. Please use the ternary operator to solve this question. Dont use if-else.

// Write your function here
function ...



// Here we will test our function with some input values
let geometryScore = 55;
@McLarenCollege
McLarenCollege / function hw1.md
Last active May 31, 2021 06:51
function homework

Write a function named getTicketPrice() that accepts age and day as arguments and returns the ticket price base on the following rules.

  • Children (age <=12) the ticket price is always 50.
  • For senior citizens(age greater than or equal to 65) if it is weekend(Saturday/Sunday) the price is 70 and for other days the price is 80.
  • For anyone else the price is 100.
let age=35;
let day ="Monday";
function getTicketPrice(age,day){
@McLarenCollege
McLarenCollege / boxesInRowsWithoutMax.js
Last active May 12, 2021 10:54
Boxes in Rows without calculating max
function boxesRows(boxes) {
let result = [];
while (1) {
let count = 0;
let zeroBoxCount = 0;
for (let i = 0; i < boxes.length; i++) {
if (boxes[i] > 0) {
boxes[i]--;
count++;
} else {