What's wrong with my code?

The objective is to: 1. Write a for loop that will generate a “lane” for each frog. Each lane should be an li and inside each li there should be a span for the lane number. There is a variable called FROGS in exercise-1/app.js. Use that to determine how many times to run the for loop.

  1. Each lane should be an li.

  2. Inside each li there should be a span that contains the lane number.

We are going to need to target each lane separately at some point in our program. So let’s give each lane its own id as well.

  1. Assign each lane an id following the this pattern: lane-<LANE_NUMBER>. e.g. lane-1, lane-2, lane-3.

  2. If you preview the page, you should now see an ordered list, with the lane number as its only value.

This is my code:
const FROGS = 3
for (let count = 1; count <= FROGS; count++) {
let li = “lane”;
li.id = “lane-” + count;
li.value = count;
}
console.log(“lane-” + li);

This looks like it may be schoolwork. If it is, we unfortunately cannot help you to respect academic integrity.

1 Like

@kyndra_laurie ,

Not sure if it can help in your learning, but you can take the following code for your reference.

const FROGS = 3; let listItem = "<ol>\n"; for (let count = 1; count <= FROGS; count++) { listItem += "<li id='lane-" + count + "'>" + count + "</li>\n"; } listItem += "</ol>" console.log(listItem);

Not exactly sure what do you require as the code above is basically typed out while interpreting your post questions. Hope it helps somehow.

Well, it’s a free course i’m taking in my free time, but I’m treating it like “school work” (i.e. setting daily agendas, deadlines to submit assignments), so idk if that goes against communite guidelines…

If it isn’t associated with any academic institution, it’s fine to get help here (it doesn’t go against our Community Guidelines).


It might help you to break down the instructions so it’s easier to understand the requirements.

  • You need to have <li> elements.
  • The number of <li> elements you will have is equals to the value of the FROGS variable.
  • You should use a for loop to generate these <li> elements.
  • Each <li> should contain a <span> element that will display the lane number.
  • Each <li> should have an ID with the value lane-<LANE_NUMBER>.

It seems that the FROGS variable has already been declared and assigned a value for you, and you do not need to create it yourself. Additionally, you need to be creating HTML tags in your code rather than simply creating strings.

What does this part mean?
let listItem = “

    \n”;

@kyndra_laurie good question that you asked!

You can try removing it and see what happens next :smile: then from there you’ll understand the wonders of the code that powered the web applications from day-to-day. Good luck on that!

Practically learning is always the best :smile:

Hey

Studying Java and total beginner, im getting so many errors on the below! - PLEASE HELP!

System.out.println(“Hey there, im Sonia, and im learning to code Java!”);

System.out.println("*");

System.out.println("***");

System.out.println("***");

System.out.println("*");

System.out.println("*");

hello there!

pardon me from saying this; but Java and JavaScript are different languages hence you can have this post shifted to the Java community and have them answer your question if possible.

Also, as you post this question do state your error messages that you received so the community can better provide you insights on how to navigate the problem you’re solving.

thanks! :slight_smile: