wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (result = 79)
if (result == 79)
Use ==.
Scala
local count = 54
local count = 54
Correct.
Lua
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<person><name>world</name><desc>47</desc></person
<person><name>world</name><desc>47</desc></person>
Add closing >.
XML
val b = 91; b = 55
var b = 91; b = 55
Use var for reassignment.
Scala
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
assert num > 53
assert num > 53
Correct.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
if c = 20 {{}}
if c == 20 {{}}
Use ==.
Swift
if (val = 31)
if (val == 31)
Use ==.
R
int temp = 'test';
String temp = 'test';
Type mismatch.
Dart
for (int i=0; i<82; i++) {{}}
for (int i=0; i<82; i++) {{}}
Correct.
Java
function bar(bar:string){{return bar;}} bar(63);
function bar(bar:string){{return bar;}} bar('test');
Pass correct type.
TypeScript
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let foo = 11; foo += 1;
let mut foo = 11; foo += 1;
Need mut to modify.
Rust
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
x := 33
x := 33
Correct.
Go
INSERT INTO users VALUES ('message',9)
INSERT INTO users (age, email) VALUES ('message',9);
Specify columns.
SQL
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(36);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(36, () => console.log('listening'));
Add callback.
Node.js
<note name='world'/>
<note name="world"/>
Double quotes.
XML
List(94,41,39)
List(94,41,39)
Correct.
Scala
data(39)
if length(data) >= 39, data(39), end
Check length.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
name: info age: 30
name: info age: 30
Correct.
YAML
cin >> result;
int result; cin >> result;
Declare variable.
C++
'message' + 46
'message' + str(46)
Can't add int to string.
Python
if z > 17 print('test')
if z > 17: print('test')
Colon missing after if.
Python
function foo(): void {{ return 83; }}
function foo(): number {{ return 83; }}
Return type mismatch.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
if result = 62:
if result == 62:
Use == for comparison.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if (c = 11)
if (c == 11)
Use ==.
C++
print 'info'
print 'info';
Add semicolon.
Perl
let result = 65; let result = 46;
let result = 65; result = 46;
Duplicate declaration.
JavaScript
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
if ($result = 42) {{}}
if ($result -eq 42) {{}}
Use -eq.
PowerShell
DELETE FROM users WHERE status=79
DELETE FROM users WHERE status=79;
Add semicolon.
SQL
bar = 29
bar=29
No spaces.
Shell
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
list[68]
if (length(list) >= 68) list[68]
Check length.
R
status: value title: hello,
status: value title: hello
Remove comma.
YAML
function compute() {{ echo 'world'; }}
function compute() {{ echo 'world'; }}
Correct.
PHP
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
{{'name':47, 'id' 38}}
{{'name':47, 'id':38}}
Colon missing.
Python
if y = 76
if y == 76
Use ==.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
'60' + 56
60 + 56
Avoid string coercion.
JavaScript
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
jwt.sign({{id:35}}, 'secret');
jwt.sign({{id:35}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
let a = 'hello'
let a = "hello"
Double quotes.
Swift
if (foo = 2) {}
if (foo == 2) {}
Use ==.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class User {{ int data; }};
class User {{ public: int data; }};
Make public.
C++
JOIN products ON items.id = products.name
JOIN products ON items.id = products.name
Correct.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (temp = 7) {{}}
if (temp === 7) {{}}
Use === for equality.
JavaScript
var x = 1;
var x = 1;
Correct.
Dart
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
print('hello')
print('hello')
Correct.
R
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let item: number = 'value';
let item: string = 'value';
Fix type.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
switch(val){{ case 81: break; }}
switch(val){{ case 81: break; default: break; }}
Add default case.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if [ $a = 53 ]; then
if [ "$a" = 53 ]; then
Quote variable.
Shell
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
{{"id":"info" "age":95}}
{{"id":"info", "age":95}}
Add comma.
JSON
data = world
data = 'world'
Quote strings.
Python
else print('data')
else: print('data')
Colon after else.
Python
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
print 'output'
print('output')
print needs parentheses.
Python
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
let b = 39;
let b = 39;
Correct.
JavaScript
y == '61'
y === 61
Use strict equality.
JavaScript
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
b > 92 & y < 31
b > 92 and y < 31
Use 'and' not '&'.
Python
[41, 33, 87
[41, 33, 87]
Close bracket.
Ruby
for num in range(31) print(num)
for num in range(31): print(num)
Colon after for.
Python
let temp: number | null = null; temp.toFixed(66);
let temp: number | null = null; if(temp!==null) temp.toFixed(66);
Null check.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
["message", 20]
["message", 20]
Correct.
JSON
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
String c = 'world';
String c = "world";
Double quotes.
Java
while temp > 75 temp -= 1
while temp > 75: temp -= 1
Colon missing after while.
Python
function handle() {{ return {{key:'result'}} }}
function handle() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if ($z = 47)
if ($z == 47)
Use ==.
Perl