###前提・実現したいこと
ラズベリーパイ3上でnote.jsをつかったプログラムを書いています。
書いて実行した際、次のようなエラーメッセージが発生しました。
どこが原因なのか教えてください。
###発生している問題・エラーメッセージ
pi@raspberrypi:/robo/spr/r-weather_data $ node ./weather-anls2.js /robo/spr/r-weather_data/weather-anls2.js:57 funstion(callback){ ^ [注)"{"を指しています] SyntaxError: Unexpected token { at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:140:18) at node.js:1043:3
###該当のソースコード
初心者のため、見づらい箇所があると思います。申し訳ないです。
var async = require('async'); function CheakWeatherType(weatheraaa){ //200-299 雷雨 Thunderstorm if (weatheraaa >= 200 && weatheraaa <= 299) { var weathertype = "Thunderstorm"; //300-399 霧雨 Drizzle }else if (weatheraaa >= 300 && weatheraaa <= 399) { var weathertype = "Drizzle"; //500-599 雨 Rain }else if (weatheraaa >= 500 && weatheraaa <= 599) { var weathertype = "Rain"; //600-699 雪 Snow }else if (weatheraaa >= 600 && weatheraaa <=699) { var weathertype = "Snow"; //700-799 外気に問題 Atmosphere }else if (weatheraaa >= 700 && weatheraaa <= 799) { var weathertype = "Atmosphere"; //800 快晴 Clear }else if (weatheraaa == 800) { var weathertype = "Clear"; //801-809 曇り Clouds }else if (weatheraaa >= 801 && weatheraaa <= 809){ var weathertype = "Clouds"; //900-909 極端 Extreme }else if (weatheraaa >= 900 && weatheraaa <= 909){ var weathertype = "Extreme"; //911-999 特殊 Additional }else if (weatheraaa >= 911 && weatheraaa <= 999){ var weathertype = "Additional"; //エラー処理(どれも一致しない) }else{ console.log("error function[CheakWeatherType] can't defined." ); } return weathertype; } //変数定義エリア var wtrcodelist = []; //天気コードリスト作成 var wtrtypelist = []; var filepath = "/tmp/weatherdata.txt" // async.series([ //◆順番にやろうねー funstion(callback){ //◆◆1つ目◆◆ ファイル取得 var fs = require('fs'); fs.readFile(filepath, 'utf8', function (err, text) { var weatherdata = text; console.log(err); }); }, function(callback){ //◆◆2つ目◆◆ ファイルを使用し出力 function(res){ for (var i=0; i<7; i++){ //i=0で 1回ごとに1足す 7になったら抜ける var weather = weatherdata[i].weather[0]; //天気情報のうち気象を抜き出してweather関数に入れてねー var wtrtype = CheakWeatherType(weather.id); //[function] タイプを分析 wtrcodelist[i] = weather.id; //weatherのid(=天気コード)をwtrcodelistのi番目に登録 wtrtypelist[i] = wtrtype; //wtrtype関数(=天気タイプ)をwtrtypelistのi番目に登録 //コンソール書き出し console.log("i = " + i); //iをコンソールへ console.log("wtrcodelist[i] = " + wtrcodelist[i]); //wtrcodelistのi番目をコンソールへ console.log("wtrtypelist[i] = " + wtrtypelist[i]); //wtrtypelistのi番目をコンソールへ console.log(); //(改行) if(i==6){ callback(null); } } } } ], //◆async最終処理に移る //チェックのためコンソール書き出し function(){ console.log(); console.log(); console.log("---------------result---------------"); console.log("wtrcodelist : " + JSON.stringify(wtrcodelist)); console.log("wtrtypelist : " + JSON.stringify(wtrtypelist)); } ) //asyncここまで
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/10/25 13:35
2017/10/25 13:50