Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 167,066
» Latest member: kclubactor
» Forum threads: 4,492
» Forum posts: 4,495

Full Statistics

Online Users
There are currently 17036 online users.
» 3 Member(s) | 17028 Guest(s)
Facebook, Bing, Google, Baidu, Applebot, rachelthomas, lucassmith, michaelwilson

Latest Threads
SELECT statement with MS ...
Forum: MS Access SQL Tutorials
Last Post: Qomplainerz
07-27-2023, 03:35 PM
» Replies: 0
» Views: 3,383
SELECT statement with the...
Forum: MS Access SQL Tutorials
Last Post: Qomplainerz
07-27-2023, 03:31 PM
» Replies: 0
» Views: 2,476
Creating hyperlinks in HT...
Forum: HTML5 Tutorials
Last Post: Qomplainerz
07-27-2023, 01:23 PM
» Replies: 0
» Views: 3,072
What's new in HTML5?
Forum: HTML5 Tutorials
Last Post: Qomplainerz
07-27-2023, 12:48 PM
» Replies: 0
» Views: 2,695
What is HTML5?
Forum: HTML5 Tutorials
Last Post: Qomplainerz
07-27-2023, 12:43 PM
» Replies: 0
» Views: 2,389
Neck isometric exercises
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:44 AM
» Replies: 0
» Views: 2,932
Shoulder shrug
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:43 AM
» Replies: 0
» Views: 2,232
Neck retraction
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:43 AM
» Replies: 0
» Views: 2,331
Neck flexion and extensio...
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:42 AM
» Replies: 0
» Views: 2,438
Neck rotation
Forum: Exercises
Last Post: Qomplainerz
07-27-2023, 11:42 AM
» Replies: 0
» Views: 2,424

 
  JavaScript exercises and solutions - Swap two numbers
Posted by: Qomplainerz - 04-04-2023, 07:54 AM - Forum: JavaScript Tutorials - No Replies

The HTML part between the <body></body> tags looks like this:

Code:
Enter the first number here:
<br>
<input type="Text" id="Num1">
<br>
Enter the second number here:
<br>
<input type="Text" id="Num2">
<br>
<input type="button" id="submit" value="submit" onclick="SwapNumbers()"></input>
<p id="Output"></p>
<input type="button" id="reset" value="Reset" onclick="Reset()"></input>

The JavaScript part looks like this:

Code:
function SwapNumbers()
{
  Num1 = document.getElementById("Num1").value;
  Num2 = document.getElementById("Num2").value;
  Num3 = Num1;
  Num4 = Num2;
  Output = "You have entered " + Num4 + " and " + Num3;
  document.getElementById("Output").innerHTML = Output;
}

function Reset()
{
  document.getElementById("Num1").value = "";
  document.getElementById("Num2").value = "";
  document.getElementById("Output").innerHTML = "";
}

Note: The reset button and the reset function are optional in case you want to delete what you were looking for in order to look for something else.

Print this item

  JavaScript exercises and solutions - Iterating through an array with keys and values
Posted by: Qomplainerz - 04-04-2023, 07:52 AM - Forum: JavaScript Tutorials - No Replies

Code:
const Games =
      [
        "Assetto Corsa",
        "Assetto Corsa Competizione",
        "rFactor",
        "rFactor2",
        "Kart Racing Pro",
        "KartKraft",
        "vRally",
        "WRC 10",
        "F1 2023",
        "F1 2022",
        "F1 2021",
        "F1 2020",
        "F1 2019",
        "F1 2018",
        "F1 2017",
        "F1 2016",
        "F1 2015",
        "F1 2014",
        "F1 2013",
        "F1 2012",
      ];

for(i = 0; i < Games.length; i++)
  {
    document.write(i + " ");
    document.write(Games[i] + "<br>");
  }

Print this item

  JavaScript - For Loop Example
Posted by: Qomplainerz - 04-04-2023, 07:51 AM - Forum: JavaScript Tutorials - No Replies

Code:
for(let step = 0; step < 15; step++)
  {
    document.write("Making one step at a time. <br>");
  }

Print this item

  JavaScript - Do...While Loop Example
Posted by: Qomplainerz - 04-04-2023, 07:51 AM - Forum: JavaScript Tutorials - No Replies

Code:
let i = 0;

do
  {
    i += 1;
    document.write(i + "<br>");
  } while (i < 15);

Print this item

  JavaScript - While Loop Example
Posted by: Qomplainerz - 04-04-2023, 07:49 AM - Forum: JavaScript Tutorials - No Replies

Code:
let n = 0;
let x = 0;

while(n < 30)
  {
    n++;
    x += n;
    document.write("The value of n is " + n + "<br>");
    document.write("The value of x is " + x + "<br>");
  }

Print this item

  JavaScript - Continue Statement Example
Posted by: Qomplainerz - 04-04-2023, 07:49 AM - Forum: JavaScript Tutorials - No Replies

Code:
let i = 0;
let n = 0;

while(i < 15)
  {
    i++;
    if(i === 3)
      {
        continue;
      }
    n += i;
    document.write("The value of i is " + i + ".<br>");
    document.write("The value of n is " + n + ".<br>");
  }

Print this item

  JavaScript - For...Of Statement Example
Posted by: Qomplainerz - 04-04-2023, 07:48 AM - Forum: JavaScript Tutorials - No Replies

Code:
const arr = [3, 5, 7];
arr.foo = "hello";

for(const i in arr)
  {
    document.write(i + "<br>");
  }

for(const i of arr)
  {
    document.write(i + "<br>");
  }

Print this item

  JavaScript - Switch Break Statements
Posted by: Qomplainerz - 04-04-2023, 07:47 AM - Forum: JavaScript Tutorials - No Replies

The HTML part between the <body></body> tags looks like this:

Code:
What's your favorite fruit?
<br>
<input type="text" id="fruit"></input>
<br>
<input type="button" id="submit" onclick="submit()" value="submit"></button>
<br>
<p id="output"></p>

The JavaScript part looks like this:

Code:
function submit()
{
  fruitType = document.getElementById("fruit").value;
 
  switch(fruitType)
    {
      case "Oranges":
        document.getElementById("output").innerHTML = "Oranges are $0.59 a pound.";
        break;
      case "Apples":
        document.getElementById("output").innerHTML = "Apples are $0.32 a pound.";
        break;
      case "Bananas":
        document.getElementById("output").innerHTML = "Bananas are $0.48 a pound.";
        break;
      case "Cherries":
        document.getElementById("output").innerHTML = "Cherries are $3.00 a pound.";
        break;
      case "Mangoes":
        document.getElementById("output").innerHTML = "Mangoes are $0.56 a pound.";
        break;
      case "Papayas":
        document.getElementById("output").innerHTML = "Papayas are $2.79 a pound.";
        break;
      default:
        document.getElementById("output").innerHTML = `Sorry, we ran out of ${fruitType}. <br> Would you like to get anything else?`;
    }
}

Print this item

  Binary to Decimal in JavaScript
Posted by: Qomplainerz - 04-04-2023, 07:46 AM - Forum: JavaScript Tutorials - No Replies

Code:
Num001 = 0B00000000;
Num002 = 0B00000001;
Num003 = 0B00000010;
Num004 = 0B00000011;

document.write(Num001);
document.write("<br>");
document.write(Num002);
document.write("<br>");
document.write(Num003);
document.write("<br>");
document.write(Num004);

Print this item

  JavaScript - Get the length of an array
Posted by: Qomplainerz - 04-04-2023, 07:45 AM - Forum: JavaScript Tutorials - No Replies

Code:
const countries = [];

countries[0] = "Norway";
countries[1] = "Sweden";
countries[2] = "Finland";
countries[3] = "England";
countries[4] = "Scotland";
countries[5] = "Ireland";

document.write(countries.length);

Print this item