So, i tried changing a p element by calling function through getElementById(). But when i click the button nothing happens.
when i click the button it should change car brands to the length of the string and and also add lamborghini.
Here's the code:-
<html>
<head>
<script src="javascript_file.js" type="text/javascript"></script>
</head>
<body>
<h1>strings and functions</h1>
<p id="pFunction">hi</p>
<button type="button" onclick="document.getElementById('pFunction').innerHTML = 'bye'">click!</button>
<p id="slice">car brands</p>
<button onclick="sliceF">Click it!</button>
</body>
</html>
Js:-
function sliceF(){
var cars = "bmw , lamborghini , toyota";
var lengthCars = cars.length;
var sliceCars = cars.slice(6 , 16);
document.getElementById('slice').innerHTML = "the length of the string is " + lengthCars + "<br/>" + "the brand in the middle is " + sliceCars;
}