算術演算子
足し算
- 本来、変数を使う計算式も単純な数値のみの場合は、そのまま数値を計算します
- プログラム中に記述した値としての「文字列」や「数値」のことを「リテラル」と呼びます
<script> document.write('<p>',5 + 3,'</p>'); </script> </body>
JS課題13
「8 + 3 = 11」と表示させなさい
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>js13|足し算</title> </head> <body> <script> <!-- document.write("<p>8 + 3 =", 8 + 3,"<\/p>"); //--> </script> </body> </html>
JS課題14
「9 + 10 = 値」と表示させなさい
「13 + 4 = 値」と表示させなさい
「5 * 6 = 値」と表示させなさい
「8 / 2 = 値」と表示させなさい
「9 % 4 = 値」と表示させなさい「郵便番号101」と表示させなさい
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>js14|算術演算子</title> </head> <body> <script> <!-- document.write("<p>9 + 10 = ", 9+10, "<\/p>"); document.write("<p>13 + 4 = ", 13-4, "<\/p>"); document.write("<p>5 * 6 = ", 5*6, "<\/p>"); document.write("<p>8 / 2 = ", 8/2, "<\/p>"); document.write("<p>9 % 4 = ", 9%4, "<\/p>"); //--> </script> <br> <script> <!-- document.write("郵便番号 "+101); //--> </script> </body> </html>
何とか課題を解いて、アップする前にもう一度課題のページを見返したら、「リテラル」ってちゃんと読んでいませんでした。
無い脳みそで変数を使っていたので、あわててやり直しました。
これからは、ちゃんと解説を読んでから課題をやります!