Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialchello yana
8,924 Pointsfor loop
Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method. To above quetion is why is my code not correct? CODING. var num=""; for(var i=4;i<=156; i++) { num += '<div>' + i + '</div>';
} console.log(num); in my personal editor it print numbers from 4 to 156 output.:: 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
2 Answers
behar
10,799 PointsHey chello! Your for loop is fine, the problem is that the challenges wants you to log each of the numbers separately so dont assign it to the variable num and then print num. Instead just do it like this:
for (var i=4;i<=156; i++) {
console.log(i) // This will in each iteration of the for loop, log whatever i is at that time, ie 4, 5, 6, 7, 8 etc.
}
Hope this helps!
chello yana
8,924 Pointsthank you