Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranoua Lachheb #20

Open
wants to merge 22 commits into
base: ranoualachheb
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions warmUp1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
// 1-using + operator combine your partner first and last name .
'lachheb'+ 'ranoua'
// 2-find if the number 13 is a multiple of 3 or not.
function multiple(n) {
if (13/3 === 0) {
return '13 is multiple of 3'
} else{
return '13 is not multiple of 3'
}

}
// 3-calculate the average age of the follwing ages [13,14,13,15,16,17,19,13,16,15]
function average (arr){
var i = 0
var result = 0
var sum = arr.length ;
while (i<arr.length) {
var average = (arr[i]+ arr[i++]) / sum ;
result = result + average ;
i ++;
}
return result ;
}


// 4-calculate your age in seconds.
// 20*365*24*60*60


// your code is here
42 changes: 42 additions & 0 deletions warmUp2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 1 - Complete the function cube that returns the cube of x:

function cube(x) {
return x*x*x ;
// your code here
}

// 2 - Write a function sameLength that accepts two strings as arguments, and returns true if those strings have the same length, and false otherwise.
function sameLength(str1,str2){
if (str1.length === str2.length){
return true ;
}
return false ;
}

// 3 - Write a function called scoreToGrade that accepts a number as a parameter and returns a string representing a letter grade corresponding to that score.

function scoreToGrade(number) {
if (number === 0 ) {
return 'F';
} else if (number < 60 ){
return 'B' ;
} else {
return 'A' ;
}
// your code here
}
// USE RECURSION
// Repeating a String n Times: Let's write a function called repeatString that takes two parameters: a string str, which is the string to be repeated, and count -- a number representing how many times the string str should be repeated
// repeatString('dog', 0); // => ''
// repeatString('dog', 1); // => 'dog'
// repeatString('dog', 2); // => 'dog' + 'dog' => 'dogdog'
// repeatString('dog', 3); // => 'dog' + 'dog' + 'dog' => 'dogdogdog'

function repeatString(str, count) {
var string = ''
if ( count === 0){
return string ;
}
return string = str + repeatString(str, count-1)
// TODO: your code here
}
46 changes: 46 additions & 0 deletions warmUp3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 1 - Write functions larger and smaller that each accept two strings as arguments, and return the larger and smaller strings, respectively
function larsma(str1,str2){
if (str1.length> str2.length){
return str1 + ' '+ str2
}
}
// 2 - Write a function called counter that, when invoked, always returns a number that is one more than the previous invocation. For instance:
<<<<<<< HEAD
// function counting(n) {
function counter(n){
return n+1
}
// }
// counting(5); // => '1, 2, 3, 4, 5'
// counting(1); // => '1'
=======
// function counting(n) {
// TODO: your code here
// }
// counting(5); // => '1, 2, 3, 4, 5'
// counting(1); // => '1'
>>>>>>> bb8f600beae6ba6bb118e46f212284106e2681e3
// counting(3); // => '1, 2, 3'

// 3 - Meet & Greet: n numbers are coming to a party for numbers. Introduce them each to all the guests as they arrive. You should end up with output looking something like this one for n = 5
i saw the solution for this exercice and i still didnt get it.. sorry :p

// welcome 1
// welcome 2, meet 1
// welcome 3, meet 1 and 2
// welcome 4, meet 1, 2 and 3
// welcome 5, meet 1, 2, 3 and 4
//

// 4- Write a function shortestWord that works like longestWord, but returns the shortest word instead.
<<<<<<< HEAD
function shortestword(str,str1){
var total = ''
if (str.length < str1.length){
total = total + str
}
return total ;
}

=======
>>>>>>> bb8f600beae6ba6bb118e46f212284106e2681e3
8 changes: 8 additions & 0 deletions warmUp4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 1-write a function that returns the product of any number by 3.

// 2-complete the following function multiply to return the result of multiplying of x and y

// 3-complete the following function that Convert Fahrenheit to Celsius if the module for converting is
// (5/9) * (fahrenheit-32);

// 4-Define a function named "sqArea", and make it display square area if you knew the length of its side.
49 changes: 49 additions & 0 deletions warmUp5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 1) Write a function named greaterNum that:
// - takes 2 arguments, both numbers.
// - returns whichever number is the greater (higher) number.
function greaterNum (x,y){
if (x>y){
return x;
} else {
return y ;
}
}
// ex greaterNum(5, 10) => "The greater number of 5 and 10 is 10."

// 2) Write a function named isEven using for loop that
// - iterate from x to y.
// - return array contain the even values,
// ex: isEven(1,10) => [2,4,6,8,10]

function isEven(x,y){
var arr = []
for (var i=0 , i<y , i++){
if(x % 2 === 0){
arr = arr.push(x) ;
}
}
return arr ;
}

// }
//3) write a function named sum that
// - Use a while loop to add up the numbers from x to y.
// ex sum(1,5) => 15

//4) Write a function named factorial that
// - Use Recursion to calculate the factorial of a number
// - the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n
// - 5! = 5*4*3*2*1 = 120
// ex : factorial(5) => 120

//5) write a function named decimals
//- the function will format a number up to specified decimal places
//- the function will return a string
//- if the parameters not a number return false
// ex :
// decimals(2100, 'a') ==> false
// decimals('a', 5) ==> false
// decimals(2.100212, 2) ==> '2.10'
// decimals(2.100212, 3) ==> '2.100'
// decimals(2100, 2) ==> '2100.00'
//
32 changes: 32 additions & 0 deletions warmUp6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Style your code and explain it step by step before jumping to code :D
// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\

// 1-Define a function called myTrueFun that returns true whenever its called.
function myTrueFun(){
return true ;
}

// 2- Define a function called color in which returns true if type of the input is string and returns false otherwise.
function color(str){

}

// 3-Write a JavaScript function that accepts a number as a parameter and check if the number is prime or not.
function javascript(n){
if (n === 0 || n === 1){
return "not a prime number"
} else if (n % 2 === 0 ) {
return "a prime number";
} else {
return "not a prime number"
}
}

// 4-write a function that accepts two numbers as parameters and returns true if the two parameters have the same value , false if not
function js (a,b){
if (a === b){
return true
} else {
return false
}
}
41 changes: 41 additions & 0 deletions warmUp7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 1-Choose the correct comparison operator to display "true", when: 5 is less than 7.
//answer :
function comparison(a,b){
if ((a===5) && (b===7)){
return a<b
}
}
//2- Write a function named helloWorld that:
//takes 1 argument, a language code (e.g. "fr", "es", "en")
//returns "Hello, World" for the given language, for atleast 3 languages. It should default to returning English.
//ex: helloWorld('fr') ==> 'Bonjour tout le monde'
// helloWorld('es') ==> 'Hola, Mundo'
// helloWorld('') ==> 'Hello, World'
function helloWorld(str){
var result = "";
switch(str) {
case "fr":
result = "bonjour tout le monde";
break;
case "esp":
result = "hola mundo";
break;
default:
result= "hello world";
break;

}
return result;
}

//3- write a function to Reverse an array without use array.reverse() method:
// ex: reverseArray([1,2,3]) ==> [3,2,1]
function reverse(array){
var arr=[]
var i = 0 ;
while( i < array.length ) {
arr.unshift(array[i])
i++;
}
return arr;
}
8 changes: 8 additions & 0 deletions warmUp8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 1 - Write a function named objKey that take an object as a parameter and returns an array containing the keys of the object
// objKey({name:'ahmed',age:20}) ==> ['name','age']

// 2 - Write a function named objLength to get the length of a JavaScript object
// objLength({name:'ahmed',age:20}) ==> 2

// 3 - Write a function named objSort to sort an array of JavaScript objects based on the id
// objSort([{id:2,value:50},{id:0,value:70},{id:1,value:40}]) ==> [{id:0,value:70},{id:1,value:40},{id:2,value:50}]
54 changes: 54 additions & 0 deletions warmUp9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Style your code and explain it step by step before jumping to code :D
// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\

//1. Write a JavaScript function to check whether an `input` is an array or not
// ex isArray([1,2])=>true
// isArray(5)=>false
// i found this function in mdn
function isArray(arr){
return array.isArray(arr)
}



// **************** git status ****************
// **************** git add fileName.js ****************
// **************** git status ****************
// **************** git commit -m "your message" ****************
// **************** git status ****************
// **************** git push origin master ****************

//2-Write a JavaScript function to get the first n element of an array.
//ex first([1,2,3],1)=>[1]
// first([1,2,3,4]2)=>[1,2]
// SO i put i<n as a stop condition so whenever i reaches the n element it stops.. before doing so it pushes every number it loops on which is less than n in the new array1 ad then returns it
function first(arr,n){
var array1=[]
for (var i=0 ; i<n; i++){
array1.push(arr[i])
}
return array1
}

// **************** git status ****************
// **************** git add fileName.js ****************
// **************** git status ****************
// **************** git commit -m "your message" ****************
// **************** git status ****************
// **************** git push origin master ****************

//3- Write a JavaScript function to convert an object into a list of `[key, value]` pairs
//ex: convert({name:'ahmed',age:20})=>[['name','ahmed'],['age', 20]]
function javascript(obj){

}
// **************** git status ****************
// **************** git add fileName.js ****************
// **************** git status ****************
// **************** git commit -m "your message" ****************
// **************** git status ****************
// **************** git push origin master ****************



// i can do this i just need more time