前提・実現したいこと
初心者です
変数が定義されていないとエラーが出ていて困っています
発生している問題・エラーメッセージ
Uncaught ReferenceError: ・・・ is not defined
該当のソースコード
JavaScript(HTMLに埋め込み)
1<!doctype html> 2<html class="no-js" lang=""> 3 4<head> 5 <meta charset="utf-8"> 6 <title></title> 7 <meta name="description" content=""> 8 <meta name="viewport" content="width=device-width, initial-scale=1"> 9 10 <meta property="og:title" content=""> 11 <meta property="og:type" content=""> 12 <meta property="og:url" content=""> 13 <meta property="og:image" content=""> 14 15 <link rel="manifest" href="site.webmanifest"> 16 <link rel="apple-touch-icon" href="icon.png"> 17 <!-- Place favicon.ico in the root directory --> 18<style> 19 20</style> 21 <!-- CSS only --> 22<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> 23 24 <meta name="theme-color" content="#fafafa"> 25</head> 26 27<script type="text/javascript" language="javascript"> 28 function entano(){ 29var kokugos = document.getElementById("kokugos").value; 30var kokugoh = document.getElementById("kokugoh").value; 31var rika1s = document.getElementById("rika1s").value; 32var rika1h = document.getElementById("rika1h").value; 33var rika2s = document.getElementById("rika2s").value; 34var rika2h = document.getElementById("rika2h").value; 35var tiris = document.getElementById("tiris").value; 36var tirih = document.getElementById("tirih").value; 37var rekisis = document.getElementById("rekisis").value; 38var rekisih = document.getElementById("rekisih").value; 39var daisuus = document.getElementById("daisuus").value; 40var daisuuh = document.getElementById("daisuuh").value; 41var zukeis = document.getElementById("zukeis").value; 42var zukeih = document.getElementById("zukeih").value; 43var eigos = document.getElementById("eigos").value; 44var eigoh = document.getElementById("eigoh").value; 45var kagis = document.getElementById("kagis").value; 46var kagih = document.getElementById("kagih").value; 47var onngakus = document.getElementById("onngakus").value; 48var onngakuh = document.getElementById("onngakuh").value; 49var bizyutus = document.getElementById("bizyutus").value; 50var bizyutuh = document.getElementById("bizyutuh").value; 51var hotais = document.getElementById("hotais").value; 52var hotaih = document.getElementById("hotaih").value; 53 54var scope = "soten"; 55soten = Number(kokugos) + Number(rika1s) + Number(rika2s) + Number(tiris) + Number(rekisis) + Number(daisuus) + Number(zukeis) + Number(eigos) + Number(kagis) + Number(onngakus) + Number(bizyutus) + Number(hotais); 56 57var heikin; 58heikin = Number(kokugoh) + Number(rika1h) + Number(rika2h) + Number(tirih) + Number(rekisih) + Number(daisuuh) + Number(zukeih) + Number(eigoh) + Number(kagih) + Number(onngakuh) + Number(bizyutuh) + Number(hotaih); 59 60var syusoten; 61syusoten = Number(kokugos) + Number(rika1s) + Number(rika2s) + Number(tiris) + Number(rekisis) + Number(daisuus) + Number(zukeis) + Number(eigos); 62 63var syuheikin; 64heikin = Number(kokugoh) + Number(rika1h) + Number(rika2h) + Number(tirih) + Number(rekisih) + Number(daisuuh) + Number(zukeih) + Number(eigoh); 65 66var hukusoten; 67hukusoten = Number(kagis) + Number(onngakus) + Number(bizyutus) + Number(hotais); 68 69var hukuheikin; 70hukuheikin = Number(kagih) + Number(onngakuh) + Number(bizyutuh) + Number(hotaih); 71 72var syutokutensa; 73syutokutensa = syusoten - syuheikin; 74 75var hukutokutensa; 76hukutokutensa = hukusoten - hukuheikin; 77 78var tokutensa; 79tokutensa = soten - heikin; 80 81 82 } 83</script> 84 85<!DOCTYPE html> 86<html lang="ja"> 87<head> 88<meta charset="UTF-8"> 89<title>サンプル</title> 90</head> 91 92 93<body> 94 <!doctype html> 95 <html lang="ja"> 96 <head> 97 <meta charset="UTF-8"> 98 <title>HTML Char size Sample</title> 99 </head> 100 <body> 101 <font size="6"><b>点数記録 For Web</b></font><br> 102 103 104 <br> 105 <div class="input-group" id="kokugo"> 106 <span class="input-group-text">国語</span> 107 <input type="text" aria-label="First name" class="form-control" name="kokugos" id="kokugos" required> 108 <input type="text" aria-label="Last name" class="form-control" name="kokugoh" id="kokugoh"> 109 </div> 110 111 <div class="input-group" id="rika1"> 112 <span class="input-group-text">理1</span> 113 <input type="text" aria-label="First name" class="form-control" name="rika1s" id="rika1s"> 114 <input type="text" aria-label="Last name" class="form-control" name="rika1h" id="rika1h"> 115 </div> 116 117 <div class="input-group" id="rika2"> 118 <span class="input-group-text">理2</span> 119 <input type="text" aria-label="First name" class="form-control" name="rika2s" id="rika2s"> 120 <input type="text" aria-label="Last name" class="form-control" name="rika2h" id="rika2h"> 121 </div> 122 123 <div class="input-group" id="tiri"> 124 <span class="input-group-text">地理</span> 125 <input type="text" aria-label="First name" class="form-control" name="tiris" id="tiris"> 126 <input type="text" aria-label="Last name" class="form-control" name="tirih" id="tirih"> 127 </div> 128 129 <div class="input-group" id="rekisi"> 130 <span class="input-group-text">歴史</span> 131 <input type="text" aria-label="First name" class="form-control" name="rekisis" id="rekisis"> 132 <input type="text" aria-label="Last name" class="form-control" name="rekisih" id="rekisih"> 133 </div> 134 135 <div class="input-group" id="daisuu"> 136 <span class="input-group-text">代数</span> 137 <input type="text" aria-label="First name" class="form-control" name="daisuus" id="daisuus"> 138 <input type="text" aria-label="Last name" class="form-control" name="daisuuh" id="daisuuh"> 139 </div> 140 141 <div class="input-group" id="zukei"> 142 <span class="input-group-text">図形</span> 143 <input type="text" aria-label="First name" class="form-control" name="zukeis" id="zukeis"> 144 <input type="text" aria-label="Last name" class="form-control" name="zukeih" id="zukeih"> 145 </div> 146 147 <div class="input-group" id="eigo"> 148 <span class="input-group-text">英語</span> 149 <input type="text" aria-label="First name" class="form-control" name="eigos" id="eigos"> 150 <input type="text" aria-label="Last name" class="form-control" name="eigoh" id="eigoh"> 151 </div> 152 153 <div class="input-group" id="kagi"> 154 <span class="input-group-text">家技</span> 155 <input type="text" aria-label="First name" class="form-control" name="kagis" id="kagis"> 156 <input type="text" aria-label="Last name" class="form-control" name="kagih" id="kagih"> 157 </div> 158 159 <div class="input-group" id="onngaku"> 160 <span class="input-group-text">音楽</span> 161 <input type="text" aria-label="First name" class="form-control" name="onngakus" id="onngakus"> 162 <input type="text" aria-label="Last name" class="form-control" name="onngakuh" id="onngakuh"> 163 </div> 164 165 <div class="input-group" id="bizyutu"> 166 <span class="input-group-text">美術</span> 167 <input type="text" aria-label="First name" class="form-control" name="bizyutus" id="bizyutus"> 168 <input type="text" aria-label="Last name" class="form-control" name="bizyutuh" id="bizyutuh"> 169 </div> 170 171 <div class="input-group" id="hotai"> 172 <span class="input-group-text">保体</span> 173 <input type="text" aria-label="First name" class="form-control" name="hotais" id="hotais"> 174 <input type="text" aria-label="Last name" class="form-control" name="hotaih" id="hotaih"> 175 </div> 176 177 <center> 178 <button type="button" class="mt-3 btn btn-outline-secondary" onclick="cancan()">取り消し</button> 179 <button type="button" class="mt-3 btn btn-outline-primary" onclick="entano()">実行</button> 180 </center> 181 182 183 <script> 184 document.write(soten); 185 </script> 186 187</body> 188 189 190 191</html> 192 193 194</html>
試したこと
スコープ(?)が原因なことが多いらしいですが理解できません
補足情報(FW/ツールのバージョンなど)
エラーはchromeの開発者ツール
VScode
回答3件
あなたの回答
tips
プレビュー