Skip to content

Instantly share code, notes, and snippets.

McLarenCollege /
Created Jul 6, 2022
Ticket Price Using If Else If Part1 Solution
let age = 23;
let day = 'Monday';
let price;
if (age <= 12) {
    price = 50;
if (age >= 65) {
    if (day === 'Saturday' || day === 'Sunday') {
 price = 70;

Foundations Course Syllabus

  • Basic Data Types and Operators (String, Number, +, -)
  • Variables (Declaration, Assignment, Naming rules)
  • Compound Expressions (%, ++, --, +=)
  • Boolean data type and logical operators (or, and, not)
  • If/else and Ternary Operator
  • Functions
  • Arrays and Loops
  • Objects
  • Array and String Methods

Write down your function tracing

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

function maxwell(a, b) {
    return rossy(a) || (a > b);
McLarenCollege /
Last active Jan 18, 2022
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.


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;
View functions

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
View function

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 /
Last active Nov 24, 2022
Ticket Price Child Adult

Given a person's age and a day ,write the code for the following scenario:

If the person is an Adult (age >=18) , the ticket price on Weekends is 100 and on weekdays is 80.

If the person is a child (age <18), the ticket price is always half of the adult price for that particular day.


McLarenCollege /
Last active Dec 21, 2021
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.