Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue #4- Writing Javascript Tutorials #18

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion tutorials/javascript/posts/basic-syntax.md
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis voluptatibus veniam vero incidunt autem pariatur dolor, ut ducimus, officiis numquam temporibus? Earum quae pariatur magnam nostrum, ipsam id. Totam, fugiat.
JavaScript syntax is a set of rules. It is constructed with the following:

##JavaScript Values

It consist of two types of values: **fixed values** and **variable values**.

*Fixed values* are known as literals which include numbers and strings. Numbers can be written with or without decimals.

```
1900

23.876
```

Strings can be written using single or double quotes.

```
'Deepanjali'

"Gerangal"
```

*Variable values*, also called variables, are used to store data values.
JavaScript uses the **var** keyword to declare the variables and **equal sign (=)** to assign values to variables.

```
var new;

new = 10;
```
##JavaScript Operators

JavaScript uses arithmetic operators to compute values.

```
(31 -17) * 73
```

##JavaScript Expressions

JavaScript uses expressions to compute a value. An expression is a combination of values and operators.

```
<!DOCTYPE html>
<html>
<body>

<p>JavaScript Expressions</p>

<p id="sample"></p>

<script>
var value;
value = 5;
document.getElementById("sample").innerHTML = value * 10;
</script>

</body>
</html>
```

##JavaScript is Case Sensitive

All JavaScript identifiers are caase sensitive.

```
var firstname, firstName;
firstname = "Deepanjali";
firstName = "Lisa";
```

Here *firstname* and *firstName* are two different variables.

##JavaScript Comments

Comments are used to write code which we do not want to execute. There are 2 ways to do it in JavaScript that are:

1. //
This is generally used for single line comments.

2. /* ... */
This is used for multiple lines of comments.

Here is an example.

```
/* Here we are declaring a variable called new.
The variable new is assigned the value of 1993 */

var new; // This is declaration for the variable new

new = 1993;
```
72 changes: 71 additions & 1 deletion tutorials/javascript/posts/beginner's-guide.md
Original file line number Diff line number Diff line change
@@ -1 +1,71 @@
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat, distinctio quas alias, facilis nulla provident voluptatum veritatis atque. Impedit deserunt, tempore laudantium recusandae praesentium aliquam quisquam, odio harum hic autem!
##What is JavaScript?

JavaScript is a lightweight scripting or programming language. It is most commonly used with HTML-CSS to make the client-side scripts more interactive and dynamic.

##Why use JavaScript?

**Less server interaction** - The user input can be validated before sending it to the server. This saves the server traffic and demand. It also makes JavaScript very fast as any code function can be run immediately.

**Versatility** - JavaScript can be used in a variety of applications. It can be inserted into any webpage regarless of the file extension, unlike PHP or SSI scripts. JavaScript can also be used inside scripts written in other languages.

**Richer interfaces** - JavaScript can be used to include many interactive features on the websites such as drag-and-drop components. One can also create interfaces that react to mouse movement and keyboard interactions.


##How to add JavaScript?

In HTML, JavaScript code must be inserted between <script> and </script> tags.

```
<script>
document.getElementById("sample").innerHTML = "Beginner's guide to JavaScript";
</script>
```

It can either be placed in the <head> or the <body> section.

**JavaScript in <head>**

```
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
document.getElementById("sample").innerHTML = "Beginner's guide to JavaScript";
}
</script>
</head>

<body>
<p id="sample">Welcome!</p>

<button type="button" onclick="myFunction()">Click me</button>

</body>
</html>

```

**JavaScript in <body>**

```
<!DOCTYPE html>
<html>
<body>

<p id="sample">Welcome!</p>

<button type="button" onclick="myFunction()">Click me</button>

<script>
function myFunction() {
document.getElementById("sample").innerHTML = "Beginner's guide to JavaScript";
}
</script>

</body>
</html>

```

Another way to add JavaScript is through external file which can be saved with a `.js` extension. We just add the `myFunction()` in the .js file.