My issue
My solution to the given task is correct but it’s showing wrong please have a look why ?
Task
Using the above syntax, do the following
Create a element of type ‘p’
Assign it the id ‘paragraph2’
Assign it the content ‘Best place to learn, practice and assess myself’
Append it / add the above as a child to the element ‘paragraph1’
Solution :
// Create a new paragraph element
let para = document.createElement(‘p’);
// Assign the id ‘paragraph2’ to the paragraph
para.id = ‘paragraph2’;
// Set the content of the paragraph
para.innerHTML = ‘Best place to learn, practice and assess myself’;
// Get the element with id ‘paragraph1’
let paragraph1 = document.getElementById(‘paragraph1’);
// Append the new paragraph as a child to the element ‘paragraph1’
paragraph1.appendChild(para);
My code
// Create a new paragraph element
let para = document.createElement('p');
// Assign the id 'paragraph2' to the paragraph
para.id = 'paragraph2';
// Set the content of the paragraph
para.innerHTML = 'Best place to learn, practice and assess myself';
// Get the element with id 'paragraph1'
let paragraph1 = document.getElementById('paragraph1');
// Append the new paragraph as a child to the element 'paragraph1'
paragraph1.appendChild(para);
Learning course: Web development using JavaScript
Problem Link: CodeChef: Practical coding for everyone