repl.it
@frangel512/

LOOPS&LOGIC_PT2

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
//Exercise 1: Printing Numbers

//  for (var x = 0; x <=100; x++){
//    console.log(x);
//  }

//Exercise 2: Print out an array

// var winterMonths = ['November', 'December', 'January', 'February', 'March'];

// for (var x = 0; x <= winterMonths.length; x=x+1){
//   console.log(winterMonths[x]);
// }


//Exercise 3: Printing Even Numbers

for(x =0; x <= 100; x += 1){
  var number = x;
  //console.log(x)
  if (Math.floor(number / 2) ===  !(number / 2)){
    console.log(number);
  }
}

//method 2

// for(var i = 0; i <100; i = i + 2){
//   console.log(i)
// }

//Exercise 4: "Sentence Reverser"
// function ReverserSentence(Sentence){
//   var result = '';

//   for( var i = Sentence.length -1; i>= 1; i--){
//     //console.log(Sentence[i]);
//     result += Sentence[i];
//   }
//   return result
// }

// ReverserSentence('This is an awesome sentence!');

function ReverserSentence2(Sentence){
  var result = '';

  for( var i = 0; i < Sentence.length; i++){
    //console.log(Sentence[Sentence.length -1 -1]);
    result += Sentence[Sentence.length -1 -1];
  }
  return result
}

ReverserSentence('This is an awesome sentence!');
?