Javascript code not working with HTML


#1

I need some help.
So I finished my code, and it worked pretty good. I used a site just to test if its actually working
I wanted to run it in my browser and I watched a tutorial. I did everything needed and had done everything correctly. So , I made the fall and named it with the .html and the end
I added this code:

<html>
<head>
  <title></title>
</head>
<body>
 
<script src="script.js"></script>

</body>
</html>

As you can see, the script source is another file. (I tried this with the NetBeans IDE AND my computer files)
I run it, and there is nothing. Please help. Here is the code that I imput into the script.js file


let orderCount = 1;
const orderCar = (color, engine, design, interior, exterior) => {
   orderCount++;
   console.log(
       "Color =" + color + " | Engine = " + engine + " | Design = " + design + " | Interior = " + interior + " | Exterior = " + exterior
   );
}

orderCar(
   'Raceyellow',
   'V8',
   'FrontStripes',
   'Leather',
   'Matte'
);
//
let priceByColor = {
   Winered: 3500,
   Red: 2500,
   Yellow: 2000,
   Raceyellow: 4000,
   Black: 1000,
   White: 1500,
   Green: 3400,
};

const getColor = () => {
   return priceByColor['Raceyellow']
};
//
let priceByEngine = {
   V6: 5600,
   V8: 7200,
   V12: 9100,
};
const getEngine = () => {
   return priceByEngine['V8']
};
//

let priceByDesign = {
   FrontStripes: 300,
   BackStripes: 200,
   FullStripes: 500,
};
const getDesign = () => {
   return priceByDesign['FrontStripes']
};
//
let priceByInterior = {
   Red: 250,
   Blue: 300,
   Yellow: 150,
   Black: 200,
};

const getInterior = () => {
   return priceByInterior['Red']
};
//

let priceByExterior = {
   CarbonLook: 5800,
   Matte: 3000,
   Metallic: 4500,
   Pearlescent: 5000,
};

const getExterior = () => {
   return priceByExterior['Matte']
};
//

let priceByCar = {
   Sports: 38000,
   Super: 50000,
   Muscle: 25000,
   Classic: 42000,
   Average: 20000,
};

const getCar = () => {
   return priceByCar['Muscle']
};




//
const getTotal = () => {
   return getColor() + getEngine() + getDesign() + getInterior() + getExterior() + getCar();
};
console.log("");

console.log("The price of the whole car is " + getTotal() * 1.1);

//console.log("The car will be ready by ")
var dateObj = new Date();
var day = dateObj.getUTCDate();
var month = dateObj.getUTCMonth() + 1;
var year = dateObj.getUTCFullYear();
//newdate = year + "/" + month + "/" + day + "/";
var d = new Date();
var n = d.getFullYear();
//
console.log("");
console.log("The current date is " + year + "/" + month + "/" + day);

//
const getEstimate = () => {
   return year + "/" + month + "/" + day + "/";
};
var someDate = new Date();
var daysToAdd = 10;

someDate.setDate(someDate.getDate() + daysToAdd);
console.log("");
console.log("Car completion estimated to be at " + someDate);
console.log("")
//
console.log(" #####" + " #" + " #" + " ###" + " ######" + " ####" + " #" + " #");
console.log("#" + " #" + " #" + " #" + " #" + " #" + " #" + " #" + " #" + "#" + " #");
console.log("#" + " #" + " #" + " ###" + " #" + " #" + " #" + " #" + " #" + "#" + " #");
console.log("#" + " #" + " #" + " #" + " #" + " #" + " #" + " #" + " #");
console.log("#" + " #" + " #" + " #" + " #" + " #" + " #" + " #" + " #");
console.log(" #####" + " ####" + " ####" + " #" + " ####" + " #" + " #");
console.log("");
console.log("");
console.log(" #####" + " #" + "#" + " #####");
console.log(" #" + " #" + " #" + " #" + " #");
console.log(" #" + " #" + "####" + "#" + " #" + "###");
console.log(" #" + " #" + " #" + " #" + " #");
console.log(" #" + " #" + " #" + " #" + " #");
console.log(" #####" + " #" + " #" + " #" + " #");

(and please explain it in a simple way i am a beginner and don’t know much about this)


#2

console is a browser tool, generally used debugging. To display on a webpage, we need different functions. For example:

http://jsbin.com/yexukuv/edit?html,js,output

press the run JS button in the top.

Careful, this might not work as easy on your computer, if you include this code in a script at the top of your page, <body></body> isn’t loaded yet. Jsbin is nice in that matter, that it provides a run JS button


#3

Thanks for the reply, but I need a way to display the information that I provided when the user enters something.


#4

Enters something where and how? you could make an <input> field, you could use prompt(), there are so many ways. And it doesn’t reflect your original question

Please give some thought into your question


#5

I’m sorry. What I meant was is there another way to display the information on the site, just like console.log?
Because console.log doesnt work


#6

well, adding to a webpage isn’t a simple as console.log,look:

http://jsbin.com/yexukuv/edit?html,js,output

lets hope this is now working i right, i add code to the webpage. Its a lot more difficult.

its possible, here is some documentation to help you:

https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement