scrimba
Prompt Engineering
AI Assisted Coding
Debugging and Error Messages
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Debugging and Error Messages
Expand for more info
index.js
run
preview
console
/* Prompt GPT to fix the errors:  

- Run the function. Copy and paste the error message into ChatGPT
along with the function
- Ask the AI to explain the errors as code comments.
*/

function createCard(parentId, cardId, cardClass, title, content) {
let parentElement = document.getElementById;

let card = document.createElement('div');
card.setAttribute('id', cardId);
card.setAttribute('class', cardClass);

let cardTitle = document.createElement('h2');
cardTitle.innerText = title;
card.appendChild(cardTitle);

let cardContent = document.createElement('p');
cardContent.innerText = content;
card = cardContent;

parentElement.appendChild(card);
}

createCard('blogPreviews', 'post1', 'card', 'How to Bake Sourdough', 'A step-by-step guide to baking your own sourdough bread at home. Learn how to create your own starter, knead the dough, and bake to perfection.');

createCard('blogPreviews', 'post2', 'card', 'Gardening 101', 'Discover the joy of gardening with our easy beginner\'s guide. Learn everything from choosing the right plants, preparing the soil, to maintaining your garden.');
Console
!
TypeError: parentElement.appendChild is not a function
,
/index.html
-4:04