Guest User

Untitled

a guest
Nov 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. // Question 1:
  2. const personAge = 55
  3. const adaAge = 2
  4. // person_age = 55
  5. // ada_age = 2
  6. //
  7. // if person_age < ada_age
  8. // print "This person is younger"
  9. // elsif ada_age < person_age
  10. // print "Ada is younger"
  11. // else
  12. // print "They’re the same!"
  13. // end
  14.  
  15. if (personAge < adaAge) {
  16. console.log("This person is younger")
  17. } else if (adaAge < personAge) {
  18. console.log ("Ada is younger")
  19. } else {
  20. console.log("They are the same")
  21. }
  22.  
  23.  
  24. // Question 2:
  25. // x = 7
  26. // y = 7
  27. //
  28. // if x > y || x == y
  29. // if x > y
  30. // print "x is bigger"
  31. // else
  32. // print "x = y"
  33. // end
  34. // else
  35. // print "y is bigger"
  36. // end
  37. const x = 7
  38. const y = 7
  39. if ( x < y ) {
  40. if ( x > y) {
  41. console.log("x is bigger")
  42. } else {
  43. console.log( "x = y")
  44. }
  45. } else {
  46. console.log("y is bigger")
  47. }
  48.  
  49. //Question 3
  50. // 10.times do |i|
  51. // puts i * i
  52. // end
  53. // let i = 0;
  54. // while (i < 10) {
  55. // console.log(i * i);
  56. // i += 1;
  57. // }
  58.  
  59. // Question 4
  60. // total = 0
  61. //
  62. // (1..3).each do |i|
  63. // total = total + i
  64. // end
  65. //
  66. // puts total
  67. let total = 0
  68. for ( let i = 1; i < 4; i++ ) {
  69. total = total + i
  70. }
  71.  
  72. console.log(total)
  73.  
  74. //Question 5
  75. // while i < 3
  76. // puts "hi"
  77. // i = i + 1
  78. // end
  79. //
  80. // puts "bye"
  81.  
  82. // let i = 0
  83. // while ( i < 3 ) {
  84. // console.log("hi");
  85. // i += 1;
  86. // }
  87. // console.log("bye")
  88.  
  89.  
  90. // Question 6
  91. const fruits = ["banana", "apple", "kiwi"]
  92.  
  93. for (let fruit of fruits) {
  94. console.log(`I love ${fruit}`);
  95. }
  96. // fruits.each do |fruit|
  97. // puts "I love #{fruit}!"
  98. // end
  99.  
  100. //Question 7
  101. // Ruby
  102. //total = 0
  103. // values = [4, 6, 2, 8, 11]
  104. //
  105. // values.each do |value|
  106. // total = total + value
  107. // end
  108. //
  109. // puts total
  110. // JS:
  111. //let total = 0
  112. //const values = [4, 6, 2, 8, 11]
  113. //
  114. // for (let value of values) {
  115. // total = total + value
  116. // }
  117. //
  118. // console.log(`${total}`)
  119.  
  120. // Question 8
  121. const values = [8, 5, 3, 10, 14, 2]
  122. for (let value of values) {
  123. if (value == 10) {
  124. console.log("Special case!")
  125. } else {
  126. console.log(`regular values like ${value}`)
  127. }
  128. }
  129. // values.each do |value|
  130. // if value == 10
  131. // puts "Special case!"
  132. // else
  133. // puts "Regular values like #{value}"
  134. // end
  135. // end
Add Comment
Please, Sign In to add comment