FAQ: Code Challenges - Code Challenge 13

This community-built FAQ covers the “Code Challenge 13” exercise from the lesson “Code Challenges”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn Node-SQLite

FAQs on the exercise Code Challenge 13

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

The exercise related to this Challenge question is “Using db.run()” found at https://www.codecademy.com/courses/learn-node-sqlite/lessons/learn-node-sqlite/exercises/using-db-run

Not to complicate learning, but wouldn’t an answer that is more consistent with the exercise be just as acceptable. Here is my answer.

const db = require(’./db’);

const newRow = {

name: ‘Brooklyn Bridge’,

year: 1883

}

db.run(“INSERT INTO Bridge (name, year) VALUES ($name, $year)”, {

$name: newRow.location,

$year: newRow.year

});
image

1 Like

Can anyone tell what is wrong with my code? The top one is the solution provided by Codecademy. The bottom one is my code and it generates an error. Why?

It looks like you used ‘backticks’, and they used “double quotes.”

Without more context, that is the only difference I notice immediately.

Rick

Pauwou,
Which code editor are you using? I love VSCode because I can put in my code in one file and the solution in a second file and compare the two side by side. VSCode even highlights the differences for me.
Rick

I am using the Codecademy editor on the website.

Looking at the examples provided throughout the course Codecademy uses both backticks and quotations marks. Therefore I assumed itt shouldn’t matter if you use backticks or quotation marks, right? As long as your consistent.

Well, quotes come in two varieties ‘single’ and “double.” However, Backticks are something different. Backticks are typically found on the top left of your keyboard. The ( ~ ) is on the same key. Whereas ‘single’ and “double” quotations are located together on their own single key typically next to the “Enter” key. You are correct that in many cases single or double quotes might be interchanged without consequences. But, employing Backticks is interpreted as template literals vs string interpolation. i.e. backticks change the meaning of your code.

below is the vscode “compare” option that lets me compare my code to the answer to hunt for differences.
You may want to consider downloading VSCode and when faced with challenging bugs in your code use the provided solution next to your code to reveal the differences. VSCode is a free code editor.

Below, at the time of this writing, I’m working on The X-Press project. Notice at the top I can see my artist.js, series.js files on the left and the current file I’m working on “issues.js” located on the far right. I can use my work from the left two files to help remind me of syntax and other helpful hints without looking at the actual answers provided by Codecademy. Note the size of each window is adjustable.


Here I’ve adjusted the window size to focus on the center file “series.js”

Here is another example of my work on the left and the solution (Hidden) on the right. I can hide that solution from my own sight so I don’t “cheat” or shortcut my learning but at the same time, in a pinch or tough spot, view that solution as needed.

Here is the same window with the Codecademy solution revealed on the right. I can see the differences quickly and easily. In this example, I used a fat arrow and the solution used the “function” terminology. Either will work but I can “see” what Codecademy considered the “best” solution and compare it to my own.

In the final pic below I’ve right-clicked on the file I want to “compare” and selected the appropriate option. The “Compare with Selected” and “Select for Compare” reveal the differences in code. Whereas the “Open to the Side” will allow me to open multiple files side by side without pointing out differences.

Hope this helps you.
Academic Coding High Five
Rick

Thanks for your quick and extensive explanation! I am already using VSCode. But it is always nice to get some more tips how to use VSCode.

I also have to correct myself, because I used single quotes and not backticks. So, the frustration about the Codecademy portal remains with regard to the flagging of errors where there are none.

Hey @pauwou,
I had the same issue: been using single quotes (not backticks) and my solution did not pass. I just assume it’s Codecademy’s module that is too rigid since I had solutions like this one, from Exercise 10, working perfectly:

averageTemperatureByYear.forEach(row => {
  db.run('INSERT INTO Average (year, temperature) VALUES ($year, $temp)', {
    $year: row.year,
    $temp: row.temperature
  }, err => {
    if (err) {
      console.log(err);
    }
  });
});

Seems like they want us to write it in a certain manner… but as long as it runs, I don’t see a problem with coding it another way. As long as we are consistent throughout our files, of course.