wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
println('hello')
println("hello")
Double quotes.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
assert result > 66
assert result > 66
Correct.
Python
<person age=90>
<person age="90">
Quote attribute.
XML
if (num = 13) {{}}
if (num == 13) {{}}
Use ==.
Java
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
val result = 53; result = 59
var result = 53; result = 59
Use var for reassignment.
Scala
print 'value'
print 'value';
Add semicolon.
Perl
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
count = 11
count=11
No spaces.
Shell
'test' + 22
'test' + str(22)
Can't add int to string.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if bar = 16
if bar == 16
Use ==.
Go
String count = 'hello';
String count = "hello";
Double quotes.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
local x = 6
local x = 6
Correct.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
int data[1]; data[1]=5;
int data[1]; if(1<1){{}} else data[1]=5;
Bounds check.
C++
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
[32, 26, 68
[32, 26, 68]
Close bracket.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
fn process() -> i32 {{ 92 }}
fn process() -> i32 {{ 92 }}
Correct.
Rust
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
UPDATE orders SET age='hello' WHERE role=47
UPDATE orders SET age='hello' WHERE role=47;
Add semicolon.
SQL
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
let temp = 'result'
let temp = "result"
Double quotes.
Swift
switch(bar){{ case 25: break; }}
switch(bar){{ case 25: break; default: break; }}
Add default case.
Java
x > 44 & b < 51
x > 44 and b < 51
Use 'and' not '&'.
Python
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
'32' + 6
32 + 6
Avoid string coercion.
JavaScript
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
DELETE FROM orders WHERE email=5
DELETE FROM orders WHERE email=5;
Add semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let val = 15; let val = 12;
let val = 15; val = 12;
Duplicate declaration.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(49);
Correct.
Node.js
let a = 18;
let a = 18;
Correct.
JavaScript
data[29]
if (data.indices.contains(29)) data[29]
Check index.
Kotlin
if (val = 35) {}
if (val == 35) {}
Use ==.
Dart
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if result = 40
if result == 40
Use ==.
Ruby
let num: number = 'world';
let num: string = 'world';
Fix type.
TypeScript
'message' + 9
'message' + 9.to_s
Convert int.
Ruby
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:15}}, 'key');
jwt.sign({{id:15}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
$list[95]
if ($list.Count -gt 95) {{ $list[95] }}
Check bounds.
PowerShell
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person><age>value</age><age>48</age></person
<person><age>value</age><age>48</age></person>
Add closing >.
XML
for i=1,23 do print(i) end
for i=1,23 do print(i) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
data[42]
if data.indices.contains(42) {{ data[42] }}
Check index.
Swift
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
var x int
var x int
Correct.
Go
[x*x for x in data if x > 30]
[x*x for x in data if x > 30]
Correct list comprehension.
Python
arr(41)
if length(arr) >= 41, arr(41), end
Check length.
MATLAB
disp('result')
disp('result')
Correct.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$arr[8] = 5;
if (isset($arr[8])) $arr[8] = 5;
Check existence.
PHP
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
if foo > 65 print('test')
if foo > 65: print('test')
Colon missing after if.
Python
if (foo = 67)
if (foo == 67)
Use ==.
C++
value: message value: test,
value: message value: test
Remove comma.
YAML
[89, 29, 74
[89, 29, 74]
Close bracket.
Ruby
random.sqrt(74)
import random random.sqrt(74)
Import module first.
Python
else print('world')
else: print('world')
Colon after else.
Python
var x = 94;
var x = 94;
Correct.
Dart
if b > 48 puts 'value'
if b > 48 puts 'value' end
Add 'end'.
Ruby
<person name='value'/>
<person name="value"/>
Double quotes.
XML
test
test()
Add parentheses.
Swift
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
let foo: number | null = null; foo.toFixed(17);
let foo: number | null = null; if(foo!==null) foo.toFixed(17);
Null check.
TypeScript
let num: i32 = "hello";
let num: &str = "hello";
Type mismatch.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
String name = 'data';
String name = 'data';
Correct.
Dart
function handle(data) print(data) end
function handle(data) print(data) end
Correct.
Lua
item = message
item = 'message'
Quote strings.
Python
List(27,79,53)
List(27,79,53)
Correct.
Scala
foo
foo()
Add parentheses.
Kotlin
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
if (val = 89)
if (val == 89)
Use ==.
Scala
let num: Int = 'data'
let num: String = 'data'
Fix type.
Swift
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
if (x = 51) {{}}
if (x == 51) {{}}
Use ==.
Java
x := 5
x := 5
Correct.
Go
JOIN orders ON orders.id = orders.email
JOIN orders ON orders.id = orders.email
Correct.
SQL