Help me with Javascript

I’m learning Javascript these days,using The book called Dom programming art
Here is the problem,I want to use JS to create content,but nothing happen when I open my html document. What’s the problem? Thank you
Here is the code below:

window.onload=function(){
	var para=document.creatElement("p");
	var txt=document.creatTextNode("hello world");
	para.appendChild(txt);
	var testdiv=document.getElementById("testdiv");
	testdiv.appendChild(para);
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title>Test</title>
 </head>
 <body>
 <div id="testdiv">
 </div>
  <script type="text/javascript" src="scripts/example.js"></script>
 </body>
 </html>
}

you have a typo in your code. its var para= document.createElement(“p”) not var para=document.creatElement(“p”);

You missed an “e” in document.creatElemen

Hello there I started learning javascript. I still cant figure a way to get past this challenge. If anyone can help that will be great. The question below:

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.

We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = “”;
// Your code below this line
result = “myNoun” + “myAdjective” + “myVerb” + “myAdverb”;

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks(“dog”, “big”, “ran”, “quickly”);

did u try without quotes? like:
result = myNoun + myAdjective + myVerb + myAdverb;
since myNoun and others are VARIABLES
if u put something in quotes programs treat it like strings (text) so your output would be:
myNounmyAdjectivemyVerbmyAdverb
and not:
dogbigranquickly

if u want to separate them it should go like:
result = myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb;

1 Like

Thank you so much pal, you’re a life saver.

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

You can’t post raw html, since it does not display.

Copy this and paste in your code :

window.onload=function(){
var para=document.createElement(“p”);
var txt=document.createTextNode(“hello world”);
para.appendChild(txt);
var testdiv=document.getElementById(“testdiv”);
testdiv.appendChild(para);
}

Or you can type :

 function myFunction() {
        window.onload=function(){
       var para=document.createElement("p");
       var txt=document.createTextNode("hello world");
      para.appendChild(txt);
      var testdiv=document.getElementById("testdiv");
      testdiv.appendChild(para);

}
myFunction();

This is very simple

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.