Posts

JavaScript Lab 3

// Print prime Numbers... let range = 1; while (range < 10) { let count = 0; for (let i = 1; i <= range ; i++) { if (range % i == 0) { count++; } } if (count == 2) { console.log(range); } range++; } // Printing Star patten for (let i = 1; i <= 5; i++) { console.log(new Array(i + 1).join("*")); }

Javascript Lab 2

/* -------------------------------- JUST BY ADDING CONDITIONS, make the program print: "All the world's a stage, And all the men and women merely players; They have their exits and their entrances," NOTE: You must refernce x, y, and z ------------------------------------ */ let x = true let y = "5" let z = 5 if(x) { console.log('All the world\'s a stage, \nAnd all the men and women merely players;') } if (y == z) { console.log('They have their exits and their entrances,') } else { console.log('And one man in his time plays many parts') } // Exercise #3b /* -------------------------------- Change the values of a, and b so that the program prints: "Thus with a kiss, I say goodbye" ------------------------------------ */ let a = 3; let b = "Rom"; if(b.length <= 3) { console.log("Thus with a kiss, ") } if(b.length % a != 1) { console.log("I say goodbye.") } else

JavaScript Lab 1

// How to print //console.log("Hello"); // There are both string "String 1"; 'string 2'; // This is a number. 42; // Variables // var x = "One"; // console.log(x); // x = "Funny"; // console.log(x); let m = "Mottel"; const h = "goodbye"; console.log(m,h); // let , var, and const are not the same. // For now use let. // Boolean true; false; // How to make null let j; j = null; console.log(j); // // Declare the Variale. // let x = 0; // // We can Add // x = x + 5; // // Multiply // x = x * 5; // // Subtract // x = x - 5; // // divide // x = x / 4; // // Another way to add // x += 5; // // Increment and decrement // x++; // x--; // Adding boolenas // let x = true; // x += 5; // Parsing Strings // let x = "42.2"; // // x = parseInt(x); // x = parseFloat(x); // x *= 2; // x = String(x); // Number to Sting // let x = 42; // x = x.toString(); // x += "hahahahhaha"; // Casting

SQL Lab 11

/* 1. STORE PROCEDURE: count_backwards IN: Number to start from (x) IN: Number to go to (Y) Display all the numbers (inclusive) from x to y as one comma separated value Ex: x = 10, y = 5, Display: 10,9,8,7,6,5 */     drop procedure count_backwards| call count_backwards(10, 5)| CREATE PROCEDURE count_backwards(IN x INT, in y int) BEGIN DECLARE i INT DEFAULT 0;     DECLARE output TEXT;         set i = x;     if x < y then     WHILE i < y DO SET output = CONCAT_WS(", ", output, i);         SET i = i + 1;     END WHILE;     else     WHILE i > y DO SET output = CONCAT_WS(", ", output, i);         SET i = i - 1;     END WHILE;     end if;         SELECT output AS Result; END | /* 2. STORE PROCEDURE: count_funny IN: Number to start from (x) IN: Number to go to (Y) Display all the numbers (inclusive) from x to y and a special message for any number divisible by 5 Ex: x = 10, y = 0 Display: 10 <- funny

SQL Lab 10

/* 1. STORE PROCEDURE: fetch_animal_parents IN: animal id Display if both parents exist -> show parent's name (both mom and dad) Else if only one of the parent exist -> show their name Else show -> No parents */         CREATE PROCEDURE fetch_animal_parents(IN a_id INT) BEGIN DECLARE ac_name VARCHAR(50);     DECLARE am_name VARCHAR(50);     DECLARE ad_name VARCHAR(50);     DECLARE a_year INT DEFAULT 0;         #get the animal info         select child.name as "Child's name" ,             mom.name as "Mother's name" ,             dad.name as "Father's name" into ac_name, am_name, ad_name            from animal child join animal mom on child.mother_id = mom.id join animal dad on child.father_id = dad.id left join race child_race on child_race.id = child.race_id join species child_species on child_species.id = child.species_id join race mom_race on mom_race.id = mom.race_id join species mom_species on mo

SQL Lab 9

# 1. STORE PROCEDURE: list_animals # Display the list of all the animals with a name and a race CREATE PROCEDURE list_animals() BEGIN SELECT animal.name, race.name as race FROM animal join race on race.id = animal.race_id where animal.name is not null and race_id is not null; END| call list_animals| # 2. STORE PROCEDURE: fetch_animal_age # IN: Animal id # OUT: Animal age in numbers CREATE PROCEDURE count_race_by_species (IN p_species_id INT, OUT p_num_races INT)  BEGIN     SELECT COUNT(*) INTO p_num_races     FROM race     WHERE species_id= p_species_id ;                              END | SELECT id, name INTO @var1, @var2 FROM animal WHERE id = 7; SELECT @var1, @var2| CALL count_race_by_species(2, @num_cat_race)| SELECT @num_cat_race| DROP PROCEDURE animal_age| CREATE PROCEDURE animal_age (IN p_animal_id INT, OUT p_num_age INT)  BEGIN     SELECT TIMESTAMPDIFF(YEAR, dob, NOW()) INTO p_num_age     FROM animal     where animal.id = p_animal_id;   

SQL Lab 8

# 1. Show all the animals (id, name, sex) prepare query1 from 'select id, name, sex from animal'; execute query1; # 2. Show all the animals by ? race_id (id, name, sex, dob, race_name) prepare query2 from 'select animal.id, animal.name, animal.sex, animal.dob, race.name from animal join race on race.id = animal.race_id                     where race_id = ?'; set @r_id = '1'; execute query2 using @r_id; # Show all the animals by ? race_id and ? species_id (id, name, sex, race_name, species_name) prepare query3 from 'select animal.id, animal.name, animal.sex, animal.dob, race.name, species.current_name from animal join race on race.id = animal.race_id join species on species.id = animal.species_id                     where animal.race_id = ? and animal.species_id = ?'; set @r_id = 1, @s_id = 1; execute query3 using @r_id, @s_id; # 4. Which specie has less than ? males and ? females (id, name, sex, race_name, species_name) wher