記述演習


ダイアログボクックスに表示
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>あいさつを表示するスクリプト</title>
<script>
  alert('Hello World!!');
</script>
</head>
<body>
</body>
</html>
コンソールに表示
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>あいさつを表示するスクリプト</title>
<script>
  console.log('Hello World!!');
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a = 10;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a;
  a = 10;
  console.log(a);
  a = 20;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var x = 123 + 456;
  var y = '123' + '456';
  console.log(x);
  console.log(y);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a = 10;
  a = a + 5;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a = 10;
  a += 5;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a = 10;
  a = a + 1;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a = 10;
  a += 1;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var a = 10;
  a++;
  console.log(a);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ 10, 20, 30 ];
  console.log(number);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ 10, 20, 30 ];
  console.log(number[1]);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ 10, 20, 30 ];
  number[1] = 50;
  console.log(number[1]);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ 10, 20, 30 ];
  number[3] = 99;
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ 10, 20, 30 ];
  number[9] = 99;
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [];
  number[0] = 10;
  number[1] = 20;
  number[2] = 30;
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ 10, 20, 30 ];
  console.log(number.length);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
  var number = [ [ 10 , 20 , 30 ] , [ 40 , 50 , 60 ] ];
  console.log(number[0][0]);
  console.log(number[0][1]);
  console.log(number[0][2]);
  console.log(number[1][0]);
  console.log(number[1][1]);
  console.log(number[1][2]);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
var favorites = {
  food : 'カレー',
  color : '青',
  number : 7
};
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
var favorites = {
  '食べ物' : 'カレー',
  '色' : '青',
  '数字' : 7
};
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
var favorites = {
  food : 'カレー',
  color : '青',
  number : 7
};
console.log(favorites.food);
console.log(favorites.color);
console.log(favorites.number);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
var favorites = {
  food : 'カレー',
  color : '青',
  number : 7
};
console.log(favorites["food"]);
var key = 'food';
console.log(favorites[key]);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>JavaScriptの練習</title>
<script>
var favorites = {
  food : 'カレー',
  color : '青',
  number : 7
};
favorites.sports = 'サッカー';
console.log(favorites.sports);
</script>
</head>
<body>
</body>
</html>