From 1c3f4f05243fa66475fcc132856c685151126aea Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 5 Nov 2021 11:12:25 -0700 Subject: [PATCH] fix: isPrime block should cast str as num (#5680) Fixes #5678 --- generators/javascript/math.js | 2 +- tests/generators/golden/generated.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/javascript/math.js b/generators/javascript/math.js index a0c8cb426..2e3828cac 100644 --- a/generators/javascript/math.js +++ b/generators/javascript/math.js @@ -157,7 +157,7 @@ Blockly.JavaScript['math_number_property'] = function(block) { 'mathIsPrime', ['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(n) {', ' // https://en.wikipedia.org/wiki/Primality_test#Naive_methods', - ' if (n === 2 || n === 3) {', + ' if (n == 2 || n == 3) {', ' return true;', ' }', ' // False if n is NaN, negative, is 1, or not whole.', diff --git a/tests/generators/golden/generated.js b/tests/generators/golden/generated.js index 7603b8a6d..01e9bd311 100644 --- a/tests/generators/golden/generated.js +++ b/tests/generators/golden/generated.js @@ -427,7 +427,7 @@ function test_constant() { function mathIsPrime(n) { // https://en.wikipedia.org/wiki/Primality_test#Naive_methods - if (n === 2 || n === 3) { + if (n == 2 || n == 3) { return true; } // False if n is NaN, negative, is 1, or not whole.