crossline

▼変数/JavaScript▼

font-size:12px;line-height: 150%;

 

 

 

こんばんわ!!

 

 

今日はついてない1日でしたw

 

 

朝まさかの二度寝をしてしまい、バイトに遅刻しそうになり、急に雨が降ってもうそりゃ寒くて寒くて。。。などなど悪いことは重なるなあと感じましたw

 

 

 

今日の授業は、PHPでした

まだはじめの方とはいえ、そりゃ頭がいたくなりました(笑)

もうこれは毎日の積み重ねのみですね!!

 

 

『変数』は、数値や文字などを入れておくはこのようなものです

変数に値を入れるには、

a=2;

とします(代入)

 

■文字列型(シングルクォテーションで囲む)■

a = 'Hello World';

b = 'a';

 

■文字列の連結■

a = '夏';

b = '休み';

c = a + b;

 

 

 

▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

 

 

Dreamweaverを起動し、新規でHTMLを作成し、『js』ファイルの中にHTMLを保存。

 

■ダイアログボックスに表示■

HTMLに下記のように記述する

ブラウザでプレビューしてみると、この時点では何も表示されないが、更新ボタンを押すと次のような画面が出る↓

f:id:ishuko:20140523004453p:plain

 

<!DOCTYPE html>

<html lanmg="ja">

<head>

<meta charset="UTF-8">

<title>You can do it!!</title>

<script>

  alert( ' Yes, You can! ' );

</script>

</head>

<body></body>

</html>

 

 

 

■コンソールに表示■

Chromeで開いた場合

要素の検証から、Consoleをクリック↓

 

例1)

f:id:ishuko:20140523005523p:plain

 

<!DOCTYPE html>

<html lanmg="ja">

<head>

<meta charset="UTF-8">

<title>You can do it!!</title>

<script>

  console.log ( ' Yes, you can! ' ) ;

</script>

</head>

<body>

</body>

</html>

 

例2)

f:id:ishuko:20140523005832p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var a;
a = 10;
console.log ( a );
a = 20;
 console.log ( a ) ;
</script>
</head>
<body>
</body>
</html>

 

 

Consoleは、『画面上で文字として

確認できるようにする』ことがわかりますね!

 

 

以下は、ほかにこんな書き方があるよ、というちょっとした応用編です

 

1)『''』で囲まれたものは列とみなされる

f:id:ishuko:20140523010258p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var x = 123 + 456;
var y = '123' + '456';
 console.log ( x );
 console.log ( y ) ;
</script>
</head>
<body>
</body>
</html>

2)

f:id:ishuko:20140523010733p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var a = 10;
a = a + 5;   <!--/または、"a += 5;" -->
 console.log ( a ) ;
</script>
</head>
<body>
</body>
</html>

3)

f:id:ishuko:20140523011024p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var number = [ 10, 20, 30 ]
 console.log ( number ) ;
</script>
</head>
<body>
</body>
</html>

4)

f:id:ishuko:20140523011328p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var number = [ 10, 20, 30 ]
number[1] =50;
 console.log ( number[1] ) ;
</script>
</head>
<body>
</body>
</html>

5)

f:id:ishuko:20140523011533p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var number = []
number[0] =10;
number[1] =20;
number[2] =30;
 console.log ( number.length ) ;
</script>
</head>
<body>
</body>
</html>
0から2までの3つ

 

6)

f:id:ishuko:20140523012112p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</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>
[ ] [ ] ,[ ]2つあるうちの0番目(0番目と1番目がある)[ ] の0番目(0、1、2の中で)

”番号にはも含まれているので少し注意が必要”

 

7)

f:id:ishuko:20140523012412p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var favorites = {
    food : 'curry',
    color : 'blue',
    number : 7
};
console.log( favorites.food );
console.log( favorites.color );
console.log( favorites.number );
</script>
</head>
<body>
</body>
</html>

 

8)

f:id:ishuko:20140523012700p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var favorites = {
    food : 'curry',
    color : 'blue',
    number : 7
};
console.log( favorites['food']);
var key = 'food'
console.log( favorites[key] );
</script>
</head>
<body>
</body>
</html>

9)

f:id:ishuko:20140523012939p:plain

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>You can do it!!</title>
<script>
var favorites = {
    food : 'curry',
    color : 'blue',
    number : 7
};
favorites.sports = 'soccer';
console.log( favorites.sports );
</script>
</head>
<body>
</body>
</html>

 

▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

 

 

 

まだまだですが理解深めます!!

では。

GOOD NIGHT!!