0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

整数の積と比較!Number()

Last updated at Posted at 2025-02-22

整数の積と比較!Number()の落とし穴

Paizaの「A × B ≦ C」を判定する問題に挑戦したんだけど、Number()を入れ忘れて大失敗…。前にも「差と積」の問題で同じミスをしたのに、またやらかした😂 そんな学びをブログにまとめたよ!

ミスったコード

const [A, B, C] = line.split(" "); 
console.log(A * B <= C ? "YES" : "NO");  

これはA, B, Cが文字列のままなので、計算が正しく動かない!
修正後のコード

const [A, B, C] = line.split(" ").map(Number);
console.log(A * B <= C ? "YES" : "NO");

map(Number)を使えば一発で数値に変換!シンプルで読みやすい!

この手のミス、初心者あるあるじゃない?僕は2回やらかしたけど、もう忘れない…はず💦

paizaで基本マスター

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?