Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile

Create a function named isNameOddOrEven that returns whether a student's name has an odd or even number of letters. Expected return should be in the following format - string: ' has an even/odd number of letters'. This function should accept one parameter, any string that represent the name you want to check.

function isNameOddOrEven(theName){
  // if (!theName) <===> if(theName.length === 0)
  if (!theName) return `Please enter the valid name!`
  if( theName.length % 2 === 0) return `${theName} has even number of letters`
 else return `${theName} has odd number of letters`
// 1:
function sumOfThree(a, b, c){
return a + b + c;
}
sumOfThree(2, 5, 9); // => 16
// 2:
function isNameOddOrEven(name){
// if (!name) <===> if(name.length === 0)
// 1
// num1, num2, sign => are just PLACEHOLDERS, it can be any word
const doTheMath = function(num1, sign, num2){
switch(sign){
case "+":
return num1 + num2;
case "-":
return num1 - num2;
case "*":
// OBJECTS
// Objects are collections of properties and each property is represented with key-value pair.
// The representation of an object in JavaScript is curly braces {}.
// The keys are unique in an object; one key will always have just one value associated to it.
// Create an object
const product = {}; // use object literal approach or
const ironhacker = {
firstName: 'marko',
age: 39,
favorites: ['JavaScript', 'Node'],
isSatisfied: true,
worksAt: 'Google',
isRemote: false
}
// 1: Add 'React' as one more favorite tech
// Data can be organized (structured) in different ways
// The following are nested data structures that are comining everything we covered so far:
// all primitive data types as well as objects and arrays
// ******************************************************
// ****************** array of objects ******************
// ******************************************************
const students = [
// *********************************************
// ******* exercise: array of objects **********
// *********************************************
const designers = [
{ name: 'Bob', age: 17 },
{ name: 'Susy', age: 18 },
{ name: 'Ted', age: 28 },
{ name: 'Sarah', age: 25 },
{ name: 'Bill', age: 19 }
// Suspects Collection
const suspectsArray = [];
let mrGreen = {
firstName: 'Jacob',
lastName: 'Green',
occupation: 'Entrepreneur',
age: 45,
description: ' He has a lot of connections',
image:
// ***************************************************************
// 1: Capitalize each element of the array - the whole word:
// ***************************************************************
const fruits = ['pineapple', 'orange', 'mango'];
const capsFruits = fruits.map(oneFruit => {
return oneFruit.toUpperCase();
});
// ***************************************************************
// MAP: Calculate the final grade for each student in the list below.
// Grade our students based on their performance on two projects (40% of final grade)
// and their final exam (60% of final grade).
// ***************************************************************
const students = [
{
name: 'Tony Parker',
firstProject: 80,