repl.it
@isreal/

Exercises

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
bfd// ====================================================
// Write a function called `doubleIt` which accepts a `num` 
// parameter (type: number) and returns double the provided number

function doubleIt(num) {
return num * 2
}

// Test
// const result1 = doubleIt(10);
// console.log(result1);  // => 20


// =====================================================
// Write a function called `shoutThem` that accepts a `words` parameter 
// (type: array) and returns a new array where all the elements have 
// been transformed to ALL UPPERCASE. 

function shoutThem(words) {
// loop though words array 
// change words array to uppercase
// return new words array

let allCaps = [];
for ( let i = 0; i < words.length; i++ ){
   allCaps.push(words[i].toUpperCase()) 
}
return allCaps;
}

 //Test
 const result3 = shoutThem(['how', 'now', 'brown', 'cow']);
 console.log(result3);  // => ['HOW', 'NOW', 'BROWN', 'COW']
// =====================================================

// =====================================================
/*
  Define a function named `rightToVote` that receives one parameter:
    1) person - type: object
  The function should check the `age` property on `person`. If it is 18 or older, 
  return true. Otherwise, return false. If `age` is not a number, throw an error.
  
  HINT: The `typeof` operator can tell you what data type a variable is
*/ 

var pers = {
  name: 'John',
  age: 30,
};

function rightToVote() {

}

// console.log(rightToVote(pers));

// =====================================================
/*
  Define a function named `countLetters` that receives two parameters:
    1) sentence  - type: string
    2) character - type: string
  The function should return a count of every `character` present in `sentence`.

  HINT: You can access a single character in a string just like accessing an element in an array - `myString[3]` would access the third character
*/

function countLetters(sentence,character) {
  //create empty variable to hold count of char
  // loop through sentence to get each char
  // count each time char occur
  // return number of times char in sentence

  let countChar = 0;
  for ( let i = 0; i < sentence.length; i++){
     if (sentence[i] === character) {
       countChar++
     }
  }
return countChar;
}
console.log(countLetters("I am ready for this tech eval", "e"));
// =====================================================
// Write a function called `evalStudents` that accepts a `students`
// parameter (type: array of objects). Each object has the following
// structure:
//
// { name: 'john', credits: 71, graduated: false }
//
// Your function should check the `credits` prop on each student object.
// If the value is greater than or equal to 90, set the `graduated` prop
// to true. Otherwise, do nothing.

function evalStudents () {
  
}


// Test
// const students = [
//   { name: 'john', credits: 71, graduated: false },
//   { name: 'laura', credits: 95, graduated: false },
//   { name: 'rich', credits: 36, graduated: false },
//   { name: 'tauhida', credits: 90, graduated: false }
// ];
// evalStudents(students);
// console.log(students);
// =====================================================
?