Javascript
Made Easy
In HTML, JavaScript code are inserted between <script> &
</script> tags.
And the <script> tag can be written in two place
1.
Before the </head> tag.
Eg
and it will display on your browser like this below
2.
In the <body> tag.
Eg.
and it will display on your browser like this below
Using Display properties of
JavaScript
Data can be displayed in JavaScript in different ways.
1. Using innerHTML to
write into an HTML.
Eg;
and it will display on your browser like this below
You observe that the <p>
element was replaced by the answer to the solution
2. Using document.write(); to display results
Eg;
and it will display on your browser like this below
3. Using the window.alert(); to send alert messages on the browser.
Eg;
4. Using console.log();
Eg;
This method is used to display message in the console of the browser
5. Using window.prompt();
Eg;
and it will display on your browser like this below
This display method can be used as an interactive medium because
the user is required to reply.
How to Reverse string in JavaScript using While Loop
<script>
1st line:
this is function to reverse a string.
2nd line:
get the length of the string
3rd line:
save the length of the string in this value called
counter
4th line:
this is a while loop that loop as long as the counter is greater
than 0.
5th line:
this is to display the character at the
location specified by the counter value.
6th line:
this is to
decrement the value of the count
7th line:
reverseString("stanley");













No comments:
Post a Comment