This community-built FAQ covers the “Code Challenge 16” 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 16
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? 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!
Hey guys, I am trying to figure out whats the difference between ’ and ".
I have noticed that this code doesn’t work :
db.run(‘INSERT INTO BirdOfParadise (scientific_name, common_name) VALUES (‘Cicinnurus regius’, ‘king bird-of-paradise’);’);
But this code which is the same thing except using ‘’ instead of ’ works :
db.run(“INSERT INTO BirdOfParadise (scientific_name, common_name) VALUES (‘Cicinnurus regius’, ‘king bird-of-paradise’);”);
Why is that ?
Thank you!
Using Placeholders with db.run to add a row to a table?
Regarding Code Challenge 16 found at https://www.codecademy.com/paths/web-development/tracks/building-a-persistent-api/modules/learn-node-sqlite-module/lessons/node-sqlite-code-challenges/exercises/code-challenge-16
The answer considered "correct"
db.run(“INSERT INTO BirdOfParadise (scientific_name, common_name) VALUES (‘Cicinnurus regius’, ‘king bird-of-paradise’);”);
My solution considered "incorrect
Why isn’t my solution acceptable. I understand that I’ve overcomplicated the answer. But in real life would my answer also work?
Thanks for any helpful input.
I believe your code would run correctly!
I tried something similar at first, but it is best practice to simplify our code as much as possible.
I do think, however, that it’s preferable to write your placeholders inside the query, like this:
db.run(
"INSERT INTO BirdOfParadise (scientific_name, common_name) VALUES ($scientific_name, $common_name)",
{
$scientific_name: 'Cicinnurus regius',
$common_name: 'king bird-of-paradise'
}
);
I might be mistaken here, but I think it is better to have the data accessible within the scope of the query. It seems more prone to errors and confusion if we were to add a lot more code to the document.
1 Like