Git Product home page Git Product logo

javascript-intro-to-looping's Introduction

JavaScript Loops

Objectives

  • Build a for loop
  • Build a while loop
  • Build a do-while loop
  • Explain the purpose of a loop
  • Explain the difference between each type of loop in JS

Introduction

Sometimes, we need to do things repeatedly in life - our daily routines, for example. We wake up every morning. We got to work or school repeatedly. We repeatedly decide what to watch next on YouTube/Netflix.

In programming, we also often need to complete tasks repeatedly. Say we wanted to count from one to five using console.log. We could write:

console.log(1)
console.log(2)
console.log(3)
console.log(4)
console.log(5)

This logs:

1
2
3
4
5

This works, but it is very repetitive. Its also 'hardcoded' - that is to say, it will only work if we want to log the numbers 1 through 5. We could instead make this code a bit more abstract and replace the numbers with a variable, incrementing the variable after each log:

let num = 1
console.log(num)
num += 1
console.log(num)
num += 1
console.log(num)
num += 1
console.log(num)
num += 1
console.log(num)

This produces the same result as the previous logs, but we now have the ability to change what number we start counting from. If we assigned num to 5 at the beginning, we would get:

5
6
7
8
9

Cool, but we still have an issue - this code is way too repetitive. In fact, abstracting the code made it even more repetitive!

Instead of having to write the same lines over and over, we can use a loop. Loops are used to execute the same block of code a specified number of times.

In this lesson, we'll take a closer look at loops and see how they can clean up and simplify our code. This is a code-along, so follow along with the instructions in each section. There are tests to make sure you are coding your solutions correctly.

Another Example

Let's imagine we have a bunch of gifts to wrap and want to use code to keep track of the process. The gifts all happen to be the same size and shape, so for every gift, we need to cut a similarly sized piece of wrapping paper, fold it up over the edges of the gift, tape it together, and add a nice little card. Then we set the wrapped gift aside and moved onto the next gift.

In programming terms, we can think of the gifts as an array and the act of wrapping them as a function. We could, of course, write the following code:

let gifts = ["teddy bear", "drone", "doll"];

function wrapGift(gift) {
  console.log(`Wrapped ${gift} and added a bow!`);
}

We could then call wrapGift() on each gift individually:

wrapGift(gifts[0]);
wrapGift(gifts[1]);
wrapGift(gifts[2]);

But if we had more gifts, we'd have to write out more calls to wrapGift() — it would probably get tiring after a while.

This is where loops come in handy! With a loop, we can just write the repeated action once and perform the action on every item in the collection.

About Loops

JavaScript loops come in a few different flavors — namely, for, while, and do-while. We'll cover each of these kinds of loop below.

The for Loop

Of the loops in JavaScript, the for loop is the most common. The for loop is made up of four statements and has the following structure:

Syntax

for ([initialization]; [condition]; [iteration]) {
  [loopBody];
}
  • initialization
    • An expression (including assignment expressions) or variable declaration. Typically used to initialize a counter variable. This expression may optionally declare new variables with the let keyword
  • Condition
    • An expression evaluated before each loop iteration. If this expression evaluates to true, statement is executed
  • Iteration
    • A statement executed at the end of each iteration. Typically, this will involve incrementing or decrementing a counter, bringing the loop ever closer to its end
  • loopBody
    • Code which runs on every iteration as long as the condition evaluates to true

Use a for loop when you know how many times you want the loop to run (for example, when you have an array of known size).

Examples

Going back to the original counting example, we could use a for loop to count numbers:

for (let num = 1; num < 6; num += 1) {
  console.log(num)
}

The above loop will produce:

1
2
3
4
5

The same results as our initial code! In this loop design, we declare a variable, let num = 1, as the initialization. Then, we establish the condition, that num is less than 6. The third thing we do is define the iteration - num += 1. Combined, these three statements indicate that, starting at num = 1, this loop will execute over and over until the condition is no longer met. After each loop, num is incremented by 1.

With these configured, all we need to provide inside the loop is a single console.log(num). If we wanted to, we could change the initial value, the condition and/or the iteration, giving us good abstraction and flexibility.

Let's take a look at another, more complex example. The code below will print the string "Hello World!" 99 times:

// i is set equal to 1
// as long as i is less than 100 execute the code in the loopBody
// - which is print "Hello World"; increment i each time the code in loopBody is executed

for (let i = 1; i < 100; i++) {
  console.log("Hello World the " + i + " time");
}

// The above prints:
// Hello World the 1 time
// Hello World the 2 time
// Hello World the 3 time

You'll encounter for loops again when you learn about iterating through object literals.

Now, let's revisit our gift wrapping example. Given the following array:

let gifts = ["teddy bear", "drone", "doll"];

If we wanted to write a function that logged a message for each gift in the array, we would need to access each element one after the other. Sounds loopy!

let gifts = ["teddy bear", "drone", "doll"];

for (let i = 0; i < 3; i++) {
  console.log(`Wrapped ${gifts[i]} and added a bow!`);
}

The above loop will log:

Wrapped teddy bear and added a bow!
Wrapped drone and added a bow!
Wrapped doll and added a bow!

This isn't exactly what we want. If we added another gift to the array, we would have a problem. Since the conditional is i < 3, this loop will only increment i from 0 to 1 to 2 and wouldn't log the extra gift. However, if we change the condition to be based off the length of our array, we'll be in great shape:

let gifts = ["teddy bear", "drone", "doll", "bike"];

for (let i = 0; i < gifts.length; i++) {
  console.log(`Wrapped ${gifts[i]} and added a bow!`);
}

Now, no matter the length of the array, our loop will be able to iterate over every element.

To finally wrap up, we can wrap the loop in a function:

let gifts = ["teddy bear", "drone", "doll"];

function wrapGift(gifts) {
  for (let i = 0; i < gifts.length; i++) {
    console.log(`Wrapped ${gifts[i]} and added a bow!`);
  }
}

wrapGift(gifts)

TODO: Build a function forLoop. It takes an array as an argument. Start counting from 0, and, using a for loop, add a string to the array 25 times. Your for loop could look something like this:

for (let i = 0; i < 25; i++) {
  // ...
}

We don't want just any string.

  • If your i value is 1, add the string "I am 1 strange loop."
  • If your i value is anything else, add the string "I am ${i} strange loops."

Remember flow control with if and else? And how do we interpolate i?

Once the loop has finished, return the array full of strings.

The while Loop

The while loop is similar to an if statement, except that its body will keep executing until the condition evaluates to false. It has the following structure:

Syntax

while ([condition]) {
  [loopBody];
}

A while loop is often used when we don't know how many times a loop needs to run - that is, the condition is dependent on a dynamic function/return value. However, we can actually write any for loop as a while loop if we choose.

Examples

Here is our counting example as a while loop:

let num = 1

while (num < 6) {
  console.log(num)
  num += 1
}

Notice that in a for loop, the initialization, condition and iteration statements are all contained in the loop syntax. In a while loop, all three statements still exist, but the initialization is outside the loop and the iteration is inside. Only the condition is contained in the loop syntax.

One common mistake when writing while loops - we must always remember to include the iteration statement (num += 1). Otherwise, the loop will run forever!

Here is another example, this time, counting down:

let countdown = 100;

while (countdown > 0) {
  console.log(--countdown);
}

In a more complex example, we can see how while loops are handy when we don't know exactly how many times we need to loop:

function maybeTrue() {
  return Math.random() >= 0.5; // Returns a random number between 0 (inclusive) and 1 (exclusive)
}

// run until `maybeTrue()` returns `false`
// (so the body of the loop might _never_ run!)
while (maybeTrue()) {
  console.log("And I ran; I ran so far away!");
}

In this example, maybeTrue() returns true 50% of the time, and our loop runs until maybeTrue() returns false. We've used a while loop because we don't have any specific number to count up or down to in our loop — we just want it to run until the condition is no longer met. In this example, it is possible the condition will be met immediately, causing the loop to never run.

TODO: Create a function called whileLoop in loops.js. The function should take a number as an argument. Using a while loop, count down (using console.log) from the passed in number to 0. Then return the string 'done'.

The Do-While Loop

The do-while loop is almost exactly the same as the while loop, except for the fact that the loop's body is executed at least once before the condition is tested.

Syntax

The do-while loop has the following structure:

do {
  [loopBody];
} while ([condition]);

You will rarely see do-while used since very few situations require a loop that blindly executes at least once. That being said, take a look at the example below:

Example

let i = 0;

function incrementVariable() {
  i = i + 1;
  return i;
}

do {
  console.log("doo-bee-doo-bee-doo");
} while (incrementVariable() < 5);

Remember how we couldn't be sure with the plain while loop above that the body would run using maybeTrue()? With do, we can be sure that the body will run!

TODO: Define a function called doWhileLoop in loops.js. The function should take an integer as an argument. Use the incrementVariable() function (you can copy it from this README) in the condition, and console log "I run once regardless." while incrementVariable() returns a number less than the parameter received. (Your condition might look something like incrementVariable() < num.) Remember that it should also console log when receiving 0 as a parameter because the do-while runs before the condition is checked.

Conclusion

If seeing all of these new loops all at once is freaking you out, take a deep breath. Remember, 98% of the time you will want to use a for loop. A general heuristic for choosing which loop, is try a for. If using for doesn't serve your purposes, then go ahead and try a different loop. Also remember that you can always refer to documentation on these loops at any time. After some time coding in JavaScript, writing a for loop will come as naturally to you as wrapping one gift after another.

Resources

View Javascript Intro To Looping on Learn.co and start learning to code for free.

javascript-intro-to-looping's People

Contributors

7kingdavid7 avatar annjohn avatar aturkewi avatar cjbrock avatar djrockstar avatar drakeltheryuujin avatar franknowinski avatar gj avatar jd2rogers2 avatar kennedycode avatar kthffmn avatar kwebster2 avatar lizbur10 avatar maxwellbenton avatar nstephenson avatar pletcher avatar rrcobb avatar salinahum avatar samnags avatar sgharms avatar sylwiavargas avatar victhevenot avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascript-intro-to-looping's Issues

My test passes even though it has an error

This is what I'm asked for:

"TODO: Define a function called doWhileLoop in loops.js. The function should take an array as an argument. Use the maybeTrue() function (you can copy it from this README) as the condition, and remove elements from the array until the array is empty or until maybeTrue() returns false. (Your condition might look something like array.length > 0 && maybeTrue().) Finally, return the array."

Here's the code I typed which passed, even though length is misspelled, and it's not even === 0 which is what I think could be correct?

function doWhileLoop(arr){
  function maybeTrue() {
  return Math.random() >= 0.5
}
  do {
    arr.pop()
  } while ((arr.leth==20) || !maybeTrue() )

return arr
}

the third test includes false instructions

The instructions state:
Define a function called doWhileLoop in loops.js. The function should take an integer as an argument. Use the incrementVariable() function (you can copy it from this README) in the condition, and console log "I run once regardless." while incrementVariable() returns a number less than the parameter received. (Your condition might look something like incrementVariable() < num.) Remember that it should also console log when receiving 0 as a parameter because the do-while runs before the condition is checked.

However, the tests seem to be expecting that the function takes an array as an argument:

  1. loops doWhileLoop(array) removes elements from array until array is empty or until incrementVariable() returns false:

Loop should go to 100

for (var i = 1; i < 4; i++) {
console.log( "Hello World the " + i + " time" );
}

should be i<100

'learn test' faulty

While running 'learn test' I am not getting any identifier on what i am missing. only total right wrong. currently at 1 right and 2 wrong but i do not know what i am missing as the dialogue does not display errors from testing.

do while loop

Dear all

need help to solve the following question:
Define a function called doWhileLoop in loops.js. The function should take an integer as an argument. Use the incrementVariable() function (you can copy it from this README) in the condition, and console log "I run once regardless." while incrementVariable() returns a number less than the parameter received. (Your condition might look something like incrementVariable() < num.) Remember that it should also console log when receiving 0 as a parameter because the do-while runs before the condition is checked.

my code so far :
let int = 0;

function doWhileLoop(int){

do { int = int + 1;
int++;
return console.log("I run once regardless");
} while (int < 10;)
}

Special case 0 or 1?

The test says it's looking for:

"I am ${i} strange loop${i === 0 ? '' : 's'}."

But shouldn't it be looking for

"I am ${i} strange loop${i === 1 ? '' : 's'}."

?

Badly worded instructions:

TODO: Build a function forLoop. It takes an array as an argument. Start counting from 0, and, using a for loop, add a string to the array. But not just any string. If your i value is 1, add the string "I am 1 strange loop."; but if your i value is anything else, add the string "I am ${i} strange loops." to the array 25 times. (Remember flow control with if and else? And how do we interpolate i?) Then return the array.

but if your i value is anything else, add the string "I am ${i} strange loops." to the array 25 times.

I suggest: "but if your i value is anything else, add the string "I am ${i} strange loops." to your array. You should let your counter run 25 times."

doWhile test

Not sure if this was intentional or not, but for this exercise the Learn To Do instructions request to create a function called doWhile(), however the test is looking for a function called doWhileLoop(). I was stuck on this for a decent amount of time only to realize i needed to rename my function based off of the loops-test.js script. if this was intentional, kudos, because i struggled. if not, this could save other members from some struggle

Discrepancy in instructions vs loops-tests.js

Hi,

The first part of this lesson asks to build a simple for loop and add a string 25 times.
It asks the user to add the string "I am 1 strange loop." if your i value is 1, add the string "I am ${i} strange loops." every other time, and return the array.

With these criteria a possible solution should be something like:
function forLoop(array){
for(var i = 0; i < 25; i++){
array[i]= "I am ${i} strange loops.";
if(i === 1){
array[i] = "I am 1 strange loop.";
}
}
return array;
}

However this does not and will never work. Studying loops-tests.js I finally came to a correct solution of:
function forLoop(array){
for(var i = 0; i < 35; i++){
array[i]= "I am " + i + " strange loops.";
if(i === 11){
array[i] = "I am 1 strange loop.";
}
if(i === 34){
array[i] = "I am 24 strange loops."
}
}
return array;
}

I has to be 11 to work correctly, and the array needs to run 34 times, not 25. I understand the array gets sliced originally but still. I'm not sure if the intention was misdirection and actually having the user analyze loops-tests.js, but this part of the question had me stumped and gave the impression that someone made a mistake in writing this question / test code out.

Thanks for your time,
Igor Veyner

Incorrect function naming in test

In the test for the do-while loop function, the newArray is called by invoking the function doWhileLoop(array). This throws an error of doWhileLoop is undefined.
I had to change line 62 in the test from:
const newArray = doWhileLoop(array)
to:
const newArray = doWhile(array)
to get the test to pass.

Bootcamp prep url missing to fork lab

If you navigate to github.com/learn-co-students/javascript-intro-to-looping-bootcamp-prep-000 it gets 404'd. We have had a student pretty upset because they were able to get an older lab and they completed it, however the browser doesn't recognize that they completed it. I believe it was the older fork with -batch that they had forked and cloned.

Just thought i'd bring this up so that it could be fixed in case any other student gets the same issue.

Function def'n in error message

Should the following error message:

loops doWhile(array) removes elements from array until array is empty or until maybeTrue() returns false:

instead say:

loops doWhileLoop(array) removes elements from array until array is empty or until maybeTrue() returns false:

can't run tests

says local tests are passed but have nothing logged to loops.js

Need to change doWhileLoop -> doWhile

The lab specs require the final function to be doWhileLoop(n)

but the lab readme and lab spec description says doWhile(n).

Change one or the other to avoid confusion in students.

learn test results in gobbledygook error

Hi- I tried to run learn test in the console and instead of getting the numbered list and the cat, I got a bunch of white text that doesn't look normal. I skipped this lesson and the next one works fine. I think maybe Mocha is broken?

My first test has error with test-loops.js despite working function

My first test in the lab asked me to write a function that adds to an array 25 times on a loop. My function was written as follows:

  var number = ["I am a strange loop"];
  for (var i = 1; i < 25; i++){
  if (i === 1){ 
    number.push("I am 1 strange loop")
  } else {
    number.push(`"I am ${i} strange loops."`)
    }
  console.log(number);
  }
}

This function does indeed do exactly what the lab supposedly asks for however there is a TypeError.

It reads:

TypeError: Cannot read property 'slice' of undefined
at Context.it (test/loops-test.js:33:38)

The block of code related to this that I found in the test/loops-test.js:33;38 section is as follows:

describe('forLoop(array)', () => {
    it('adds `"I am ${i} strange loop${i === 0 ? \'\' : \'s\'}."` to an array 25 times', () => {
      const [array, t] = makeArray()
      const strangeArray = forLoop(array)
      const testArray = strangeArray.slice(array.length)**

      let first = "I am 1 strange loop."
      let rest = "I am 24 strange loops."

      expect(strangeArray[11]).to.equal(first)
      expect(strangeArray[34]).to.equal(rest)
      expect(strangeArray.length).to.equal(t + 25)
    })
  })

I cannot pass the lab without this error being addressed. I will attempt to figure out the issue but wanted to submit this issue as well.

Problem with IDE

Hi, I am trying to finish this lab but "learn test" is not working in the IDE. It says that the current version of Yarn is out of date?? It shows this message when I first start up the IDE:

[18:29:49] ~
// ♥ learn open javascript-intro-to-looping-bootcamp-prep-000
Looking for lesson...
Forking lesson...
Cloning lesson...
Opening lesson...
Installing npm dependencies...
yarn install v1.9.4
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear thiswarning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
warning Your current version of Yarn is out of date. The latest version is "1.10.1", while you're on "1.9.4".
info To upgrade, run the following command:
$ sudo apt-get update && sudo apt-get install yarn
Done in 3.53s.
Done.

If you could help me out, that'd be great. Thank you!

Javascript Intro to Looping - DoWhile Loop TODO - IncrementVariable

In the intro to looping, it asks for the following:

TODO: Define a function called doWhileLoop in loops.js. The function should take an array as an argument. Use the incrementVariable() function (you can copy it from this README) as the condition, and remove elements from the array until the array is empty or until incrementVariable() returns false. (Your condition might look something like array.length > 0 && incrementVariable().) Finally, return the array.

incrementVariable() is defined in the lab as:
var i = 0;
function incrementVariable() {
i = i + 1;
}

IncrementVariable() will never evaluate to false?

Not sure what they are trying to teach by adding the complication of using this function, but clearly there is a typo or bad wording here.

And the test doesn't catch it , since I mostly ignored the incrementVariable() and still passed the test.

-Roberto

Redundant declaration

Line 33 in "loops-test.js" is a redundant declaration that is not used anywehere after declaration.
const testArray = strangeArray.slice(array.length)

Updated directions need revision

@drakeltheryuujin
The updated directions for the doWhileLoop are unclear.

The incrementVariable function should not be used as a condition, as it will always return true, since all it does is increment the value of a variable. Additionally, the way it is used in the previous example in the README is not particularly relevant to the doWhileLoop function, since we are removing elements from an array (and using it correctly in this context would be pretty counterintuitive).

test for forLoop part seems flacky

the forLoop test kept saying it was expecting 25 to equal 31, next time it would be, 28, 26, or 30. I finally gave up trying to fix my code and just ran the test an couple more times, and it passed... without any code fixes.

doWhileLoop instructions need revision

(Update: nevermind I just saw that this lab has been revised. For some reason the github link was going to the old one...)

The answer can not be reasonably deduced because the directions are flawed.

"TODO: Define a function called doWhileLoop in loops.js. The function should take an integer as an argument. Use the incrementVariable() function (you can copy it from this README) in the condition, and console log "I run once regardless." while incrementVariable() returns a number less than the parameter received. (Your condition might look something like incrementVariable() < num.) Remember that it should also console log when receiving 0 as a parameter because the do-while runs before the condition is checked."

However, the test passed the function an array as an argument, NOT an integer. Following the directions will thus lead students astray and produce confusion. Please kindly fix this!

Timeout error instead of tests

I don't see the tests for each of the 3 loops, instead I see I get a timeout error

0 passing (2s)                                                                                
1 failing                                                                                     
                                                                                                
  1) loops "before all" hook:                                                                   
     Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.

A Little confused

Hello,

According to the solutions checklist I was able to solve the three TODOs for the "Javascript Intro To Looping" challenges. However, there was a prompt stating that I did not finish the assignments on that page
2020-02-27 (10)
2020-02-27 (9)

Here is my code for anyone's perusal:

function forLoop (a = []) {

for (let i = 0; i < 25; i++) {
if (i === 1) {
a.push(I am ${i} strange loop.);
} else {
a.push(I am ${i} strange loops.);
}
}
return a;
}
forLoop();

function whileLoop(n) {
let countdown = n;

while (countdown > 0) {
  console.log(--countdown);
}

return "done";
}
whileLoop();

function doWhileLoop(num) {
let i = 0;

do {
function incrementVariable() {
i = i + 1;
return i;

}
console.log(`I run once regardless.`);

} while (incrementVariable() < num);
}
doWhileLoop();

What needs to be changed as I am not entirely sure. Any response would be greatly appreciated. Thanks.

Ian

IDE Issue

In my IDE, only loop.js opens, the rest has disappeared

doWhileLoop confusion

I think there is a confusing passage in the doWhileLoop TODO instructions:
Use the maybeTrue() function (you can copy it from this README) as the condition, and remove elements from the array until the array is empty or until maybeTrue() returns false. (Your condition might look something like array.length > 0 && maybeTrue().)
Because the instructions stipulate the conditions are this OR that, it is confusing that in the example the && is used. Is this deliberate? Would not || make more sense?

Typo

At the beginning of the page, under the first logging result within the Introduction section, the word "repetitive" is misspelled in the sentence "This works, but it is very repetative." This should be fixed so that it is spelled correctly.

In addition, the next sentence also has a typo. It misspells the word "it's" as "its." Since in this context the word is meant to be the contraction of "it is," "it's" is the correct word to use.

The terminal in the IDE is not working

Whenever I run my tests from the terminal ("learn test") the program will seem to run, but then normal output, what tests passed and failed, is not delivered.

From then on, any text I type into the terminal doesn't appear in the correct place, nor does it run anything, which I've tried to capture in the attached screenshot.

screenshot from 2018-12-22 14-20-27

Typo

The 'to' in the following paragraph should be 'too':
"Cool, but we still have an issue - this code is way to repetitive. In fact, abstracting the code made it even more repetitive!"

My navigation menu for IDE is missing?

Hello, I opened up IDE to work on beatles loop lab, but I can't access any of the files because the navigation menu has gone missing. How do I bring it back? Thanks

I am 1 strange loop.

Test passes without including the condition i===1 and adding "I am 1 strange loop." to the array.
This pertains to the forLoop function.

last paragraph

"After some time coding in JavaScript, writing a for loop will come as naturally to you as writing an each loop to iterate over an array in Ruby."

Totally agree, but some users may not have taken the Ruby course?

Learn Command isn't working

The learn command isn't working. When I run it, it get's hung up:

Shana: intro-to-looping.js-v-000
♥ learn
Loading /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/lib/learn_test/strategies/jasmine/runners/SpecRunner.html
Started

..

When I run learn -b, it'll open to a new tab but also gets hung up, asking if I want to wait or kill it.

When I ctrl + C it, I get the following output:
Shana: intro-to-looping.js-v-000
♥ learn
Loading /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/lib/learn_test/strategies/jasmine/runners/SpecRunner.html
Started

..^C/Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/lib/learn_test/strategies/jasmine.rb:97:in system': Interrupt from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/lib/learn_test/strategies/jasmine.rb:97:inrun_jasmine'
from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/lib/learn_test/strategies/jasmine.rb:28:in run' from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/lib/learn_test/runner.rb:15:inrun'
from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-test-2.0.0/bin/learn-test:56:in <top (required)>' from /Users/Shana/.rbenv/versions/2.2.2/bin/learn-test:23:inload'
from /Users/Shana/.rbenv/versions/2.2.2/bin/learn-test:23:in <main>' /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-co-3.3.0/lib/learn/cli.rb:19:insystem': Interrupt
from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-co-3.3.0/lib/learn/cli.rb:19:in test' from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor/command.rb:27:inrun'
from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in invoke_command' from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor.rb:359:indispatch'
from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor/base.rb:440:in start' from /Users/Shana/.rvm/gems/ruby-2.2.1/gems/learn-co-3.3.0/bin/learn:40:in<top (required)>'
from /Users/Shana/.rbenv/versions/2.2.2/bin/learn:23:in load' from /Users/Shana/.rbenv/versions/2.2.2/bin/learn:23:in

'

But when I skip ahead to the next lesson, I can run the learn command just fine. I tried to unintall/reinstall gem learn-co.

"Learn test" faulty

Hi,

When I try to use "learn test" to test my code I am met with no response in the IDE. I have tried to refresh the page, clear my history/cookies, quitting Chrome but no luck. I am 3 sections from finishing the material I need for the technical interview. What can I do to fix this issue?

Thanks

IDE Console Issue

The Learn IDE console has been giving me many problems with coding activities. It is so difficult to know what I am doing right or wrong when I get back responses that do not reflect any of my input or no response at all.

I am unable to test my code for this activity, I am not sure if I have done it correctly.

Missing "s" from gift

I'm pretty sure there's supposed to be an "s" after "gift" in this portion of the code:

function wrapGift(gifts) {
console.log(Wrapped ${gift**s**} and added a bow!);
}

missingS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.